Migrate all DataBase to DBState

This commit is contained in:
kwaroran
2024-10-24 01:59:57 +09:00
parent 4e9190f1b5
commit b3fddb814e
65 changed files with 331 additions and 434 deletions

View File

@@ -3,8 +3,7 @@ import type { OpenAIChat } from "..";
import { HypaProcesser } from "./hypamemory";
import { language } from "src/lang";
import type { ChatTokenizer } from "src/ts/tokenizer";
import { get } from "svelte/store";
import { DataBase } from "src/ts/storage/database.svelte";
import { getDatabase } from "src/ts/storage/database.svelte";
const maxRecentChatQuery = 4;
export async function hanuraiMemory(chats:OpenAIChat[],arg:{
@@ -12,7 +11,7 @@ export async function hanuraiMemory(chats:OpenAIChat[],arg:{
maxContextTokens:number,
tokenizer:ChatTokenizer
}){
const db = get(DataBase)
const db = getDatabase()
const tokenizer = arg.tokenizer
const processer = new HypaProcesser('MiniLM')
let addTexts:string[] = []

View File

@@ -1,12 +1,10 @@
import { DataBase, type Chat, type character, type groupChat } from "src/ts/storage/database.svelte";
import { getDatabase, type Chat, type character, type groupChat } from "src/ts/storage/database.svelte";
import type { OpenAIChat } from "..";
import type { ChatTokenizer } from "src/ts/tokenizer";
import { get } from "svelte/store";
import { requestChatData } from "../request";
import { HypaProcesser } from "./hypamemory";
import { globalFetch } from "src/ts/storage/globalApi";
import { runSummarizer } from "../transformers";
import { last, remove } from "lodash";
export interface HypaV2Data {
chunks: {
@@ -20,7 +18,7 @@ export interface HypaV2Data {
}
async function summary(stringlizedChat: string): Promise<{ success: boolean; data: string }> {
const db = get(DataBase);
const db = getDatabase();
console.log("Summarizing");
if (db.supaModelType === 'distilbart') {
@@ -123,7 +121,7 @@ export async function hypaMemoryV2(
arg: { asHyper?: boolean, summaryModel?: string, summaryPrompt?: string, hypaModel?: string } = {}
): Promise<{ currentTokens: number; chats: OpenAIChat[]; error?: string; memory?: HypaV2Data; }> {
const db = get(DataBase);
const db = getDatabase();
const data: HypaV2Data = room.hypaV2Data ?? { chunks: [], mainChunks: [] };
let allocatedTokens = db.hypaAllocatedTokens;

View File

@@ -1,6 +1,5 @@
import { get } from "svelte/store";
import type { OpenAIChat } from "..";
import { DataBase, type Chat, type character, type groupChat } from "../../storage/database.svelte";
import { getDatabase, type Chat, type character, type groupChat } from "../../storage/database.svelte";
import { tokenize, type ChatTokenizer } from "../../tokenizer";
import { requestChatData } from "../request";
import { HypaProcesser } from "./hypamemory";
@@ -18,7 +17,7 @@ export async function supaMemory(
tokenizer:ChatTokenizer,
arg:{asHyper?:boolean} = {}
): Promise<{ currentTokens: number; chats: OpenAIChat[]; error?:string; memory?:string;lastId?:string}>{
const db = get(DataBase)
const db = getDatabase()
currentTokens += 10