Migrate all DataBase to DBState
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { get } from "svelte/store";
|
||||
import { DataBase, getCurrentCharacter, getCurrentChat, setCurrentChat, setDatabase } from "../storage/database.svelte";
|
||||
import { getCurrentCharacter, getCurrentChat, getDatabase, setCurrentChat, setDatabase } from "../storage/database.svelte";
|
||||
import { selectedCharID } from "../stores";
|
||||
import { alertInput, alertMd, alertNormal, alertSelect, alertToast } from "../alert";
|
||||
import { sayTTS } from "./tts";
|
||||
@@ -40,7 +40,7 @@ export async function processMultiCommand(command:string) {
|
||||
|
||||
|
||||
async function processCommand(command:string, pipe:string):Promise<false | string>{
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const currentChar = db.characters[get(selectedCharID)]
|
||||
const currentChat = currentChar.chats[currentChar.chatPage]
|
||||
let {commandName, arg, namedArg} = commandParser(command, pipe)
|
||||
@@ -180,7 +180,7 @@ async function processCommand(command:string, pipe:string):Promise<false | strin
|
||||
}
|
||||
case 'setvar':{
|
||||
console.log(namedArg, arg)
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
const chat = char.chats[char.chatPage]
|
||||
@@ -194,7 +194,7 @@ async function processCommand(command:string, pipe:string):Promise<false | strin
|
||||
return ''
|
||||
}
|
||||
case 'addvar':{
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
const chat = char.chats[char.chatPage]
|
||||
@@ -207,7 +207,7 @@ async function processCommand(command:string, pipe:string):Promise<false | strin
|
||||
return ''
|
||||
}
|
||||
case 'getvar':{
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
const chat = char.chats[char.chatPage]
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
import { DataBase, type Chat, type character } from "src/ts/storage/database.svelte";
|
||||
import { getDatabase, type Chat, type character } from "src/ts/storage/database.svelte";
|
||||
import { HypaProcesser } from '../memory/hypamemory'
|
||||
import type { OpenAIChat } from "..";
|
||||
import { stringlizeChat } from "../stringlize";
|
||||
import { get } from "svelte/store";
|
||||
import { getUserName } from "src/ts/util";
|
||||
|
||||
export async function additionalInformations(char: character,chats:Chat,){
|
||||
const processer = new HypaProcesser('MiniLM')
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
|
||||
const info = char.additionalText
|
||||
if(info){
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import localforage from "localforage";
|
||||
import { selectSingleFile } from "../../util";
|
||||
import { v4 } from "uuid";
|
||||
import { DataBase } from "../../storage/database.svelte";
|
||||
import { get } from "svelte/store";
|
||||
import { getDatabase } from "../../storage/database.svelte";
|
||||
import { checkImageType } from "../../parser";
|
||||
|
||||
const inlayStorage = localforage.createInstance({
|
||||
@@ -85,7 +83,7 @@ export async function getInlayImage(id: string){
|
||||
}
|
||||
|
||||
export function supportsInlayImage(){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
return db.aiModel.startsWith('gptv') || db.aiModel === 'gemini-pro-vision' || db.aiModel.startsWith('claude-3') || db.aiModel.startsWith('gpt4_turbo') || db.aiModel.startsWith('gpt5') || db.aiModel.startsWith('gpt4o') ||
|
||||
(db.aiModel === 'reverse_proxy' && (
|
||||
db.proxyRequestModel?.startsWith('gptv') || db.proxyRequestModel === 'gemini-pro-vision' || db.proxyRequestModel?.startsWith('claude-3') || db.proxyRequestModel.startsWith('gpt4_turbo') ||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { DataBase, setDatabase } from 'src/ts/storage/database.svelte';
|
||||
import { getDatabase, setDatabase } from 'src/ts/storage/database.svelte';
|
||||
import { selectedCharID } from 'src/ts/stores';
|
||||
import { get } from 'svelte/store';
|
||||
import { doingChat, sendChat } from '..';
|
||||
@@ -19,7 +19,7 @@ async function sendPofile(arg:sendFileArg){
|
||||
let note = ''
|
||||
let speaker = ''
|
||||
let parseMode = 0
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
let currentChar = db.characters[get(selectedCharID)]
|
||||
let currentChat = currentChar.chats[currentChar.chatPage]
|
||||
const lines = arg.file.split('\n')
|
||||
|
||||
@@ -3,11 +3,11 @@ import { findCharacterbyId } from "../util";
|
||||
import { alertConfirm, alertError, alertSelectChar } from "../alert";
|
||||
import { language } from "src/lang";
|
||||
import { get } from "svelte/store";
|
||||
import { DataBase, setDatabase } from "../storage/database.svelte";
|
||||
import { getDatabase, setDatabase } from "../storage/database.svelte";
|
||||
import { selectedCharID } from "../stores";
|
||||
|
||||
export async function addGroupChar(){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
let selectedId = get(selectedCharID)
|
||||
let group = db.characters[selectedId]
|
||||
if(group.type === 'group'){
|
||||
@@ -36,7 +36,7 @@ export async function addGroupChar(){
|
||||
|
||||
|
||||
export function rmCharFromGroup(index:number){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
let selectedId = get(selectedCharID)
|
||||
let group = db.characters[selectedId]
|
||||
if(group.type === 'group'){
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { get, writable } from "svelte/store";
|
||||
import { DataBase, setDatabase, type character, type MessageGenerationInfo, type Chat } from "../storage/database.svelte";
|
||||
import { setDatabase, type character, type MessageGenerationInfo, type Chat, getDatabase, setDatabaseLite } from "../storage/database.svelte";
|
||||
import { CharEmotion, selectedCharID } from "../stores";
|
||||
import { ChatTokenizer, tokenize, tokenizeNum } from "../tokenizer";
|
||||
import { language } from "../../lang";
|
||||
import { alertError } from "../alert";
|
||||
import { loadLoreBookPrompt, loadLoreBookV3Prompt } from "./lorebook";
|
||||
import { loadLoreBookV3Prompt } from "./lorebook";
|
||||
import { findCharacterbyId, getAuthorNoteDefaultText, getPersonaPrompt, getUserName, isLastCharPunctuation, trimUntilPunctuation } from "../util";
|
||||
import { requestChatData } from "./request";
|
||||
import { stableDiff } from "./stableDiff";
|
||||
@@ -120,7 +120,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
||||
chatProcessStage.set(0)
|
||||
}
|
||||
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
db.statics.messages += 1
|
||||
let selectedChar = get(selectedCharID)
|
||||
const nowChatroom = db.characters[selectedChar]
|
||||
@@ -783,7 +783,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
||||
currentChat.hypaV2Data = sp.memory ?? currentChat.hypaV2Data
|
||||
db.characters[selectedChar].chats[selectedChat].hypaV2Data = currentChat.hypaV2Data
|
||||
console.log(currentChat.hypaV2Data)
|
||||
DataBase.set(db)
|
||||
setDatabaseLite(db)
|
||||
}
|
||||
else{
|
||||
const sp = await supaMemory(chats, currentTokens, maxContextTokens, currentChat, nowChatroom, tokenizer, {
|
||||
@@ -798,7 +798,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
||||
currentChat.supaMemoryData = sp.memory ?? currentChat.supaMemoryData
|
||||
db.characters[selectedChar].chats[selectedChat].supaMemoryData = currentChat.supaMemoryData
|
||||
console.log(currentChat.supaMemoryData)
|
||||
DataBase.set(db)
|
||||
setDatabaseLite(db)
|
||||
currentChat.lastMemory = sp.lastId ?? currentChat.lastMemory;
|
||||
}
|
||||
chatProcessStage.set(1)
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
import { get } from "svelte/store";
|
||||
import {selectedCharID} from '../stores'
|
||||
import { DataBase, setDatabase, type Message, type loreBook } from "../storage/database.svelte";
|
||||
import { getDatabase, setDatabase, type Message, type loreBook } from "../storage/database.svelte";
|
||||
import { tokenize } from "../tokenizer";
|
||||
import { checkNullish, selectSingleFile } from "../util";
|
||||
import { alertError, alertNormal } from "../alert";
|
||||
import { language } from "../../lang";
|
||||
import { downloadFile } from "../storage/globalApi";
|
||||
import { HypaProcesser } from "./memory/hypamemory";
|
||||
import { getModuleLorebooks } from "./modules";
|
||||
import { CCardLib } from "@risuai/ccardlib";
|
||||
|
||||
export function addLorebook(type:number) {
|
||||
let selectedID = get(selectedCharID)
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
if(type === 0){
|
||||
db.characters[selectedID].globalLore.push({
|
||||
key: '',
|
||||
@@ -54,7 +53,7 @@ const rmRegex = / |\n/g
|
||||
export async function loadLoreBookPrompt(){
|
||||
|
||||
const selectedID = get(selectedCharID)
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const char = db.characters[selectedID]
|
||||
const page = char.chatPage
|
||||
const characterLore = char.globalLore ?? []
|
||||
@@ -209,7 +208,7 @@ export async function loadLoreBookPrompt(){
|
||||
|
||||
export async function loadLoreBookV3Prompt(){
|
||||
const selectedID = get(selectedCharID)
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const char = db.characters[selectedID]
|
||||
const page = char.chatPage
|
||||
const characterLore = char.globalLore ?? []
|
||||
@@ -531,7 +530,7 @@ export async function loadLoreBookV3Prompt(){
|
||||
|
||||
export async function importLoreBook(mode:'global'|'local'|'sglobal'){
|
||||
const selectedID = get(selectedCharID)
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
const page = mode === 'sglobal' ? -1 : db.characters[selectedID].chatPage
|
||||
let lore =
|
||||
mode === 'global' ? db.characters[selectedID].globalLore :
|
||||
@@ -613,7 +612,7 @@ export function convertExternalLorebook(entries:{[key:string]:CCLorebook}){
|
||||
export async function exportLoreBook(mode:'global'|'local'|'sglobal'){
|
||||
try {
|
||||
const selectedID = get(selectedCharID)
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const page = mode === 'sglobal' ? -1 : db.characters[selectedID].chatPage
|
||||
const lore =
|
||||
mode === 'global' ? db.characters[selectedID].globalLore :
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { getChatVar, hasher, risuChatParser, setChatVar, type simpleCharacterArgument } from "../parser";
|
||||
import { getChatVar, hasher, setChatVar, type simpleCharacterArgument } from "../parser";
|
||||
import { LuaEngine, LuaFactory } from "wasmoon";
|
||||
import { DataBase, getCurrentCharacter, getCurrentChat, setCurrentChat, setDatabase, type Chat, type character, type groupChat } from "../storage/database.svelte";
|
||||
import { getCurrentCharacter, getCurrentChat, getDatabase, setCurrentChat, setDatabase, type Chat, type character, type groupChat } from "../storage/database.svelte";
|
||||
import { get } from "svelte/store";
|
||||
import { ReloadGUIPointer, selectedCharID } from "../stores";
|
||||
import { alertError, alertInput, alertNormal } from "../alert";
|
||||
@@ -332,7 +332,7 @@ export async function runLua(code:string, arg:{
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
}
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
return char.name
|
||||
@@ -342,7 +342,7 @@ export async function runLua(code:string, arg:{
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
}
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
if(typeof name !== 'string'){
|
||||
throw('Invalid data type')
|
||||
@@ -355,7 +355,7 @@ export async function runLua(code:string, arg:{
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
}
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char =db.characters[selectedChar]
|
||||
if(typeof data !== 'string'){
|
||||
@@ -373,7 +373,7 @@ export async function runLua(code:string, arg:{
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
}
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
if(typeof data !== 'string'){
|
||||
@@ -389,7 +389,7 @@ export async function runLua(code:string, arg:{
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
}
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
return char.firstMessage
|
||||
@@ -399,7 +399,7 @@ export async function runLua(code:string, arg:{
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
}
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
return char.backgroundHTML
|
||||
@@ -409,7 +409,7 @@ export async function runLua(code:string, arg:{
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
}
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
if(typeof data !== 'string'){
|
||||
return false
|
||||
|
||||
@@ -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[] = []
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -4,8 +4,7 @@ import { sleep } from "src/ts/util";
|
||||
import * as path from "@tauri-apps/api/path";
|
||||
import { exists, readTextFile } from "@tauri-apps/plugin-fs";
|
||||
import { alertClear, alertError, alertMd, alertWait } from "src/ts/alert";
|
||||
import { get } from "svelte/store";
|
||||
import { DataBase } from "src/ts/storage/database.svelte";
|
||||
import { getDatabase } from "src/ts/storage/database.svelte";
|
||||
let serverRunning = false;
|
||||
|
||||
export function checkLocalModel():Promise<string>{
|
||||
@@ -130,7 +129,7 @@ export async function loadExllamaFull(){
|
||||
|
||||
|
||||
async function runLocalModelOld(prompt:string){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
|
||||
if(!serverRunning){
|
||||
await loadExllamaFull()
|
||||
@@ -273,7 +272,7 @@ export async function runGGUFModel(arg:{
|
||||
|
||||
export async function tokenizeGGUFModel(prompt:string):Promise<number[]> {
|
||||
const key = await getLocalKey()
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const modelPath = db.aiModel.replace('local_', '')
|
||||
const b = await fetch("http://localhost:10026/llamacpp/tokenize", {
|
||||
method: "POST",
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { DataBase } from "src/ts/storage/database.svelte";
|
||||
import { get } from "svelte/store";
|
||||
import { getDatabase } from "src/ts/storage/database.svelte";
|
||||
|
||||
export function getGenerationModelString(){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
switch (db.aiModel){
|
||||
case 'reverse_proxy':
|
||||
return 'reverse_proxy-' + (db.reverseProxyOobaMode ? 'ooba' : db.proxyRequestModel)
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { DataBase, setDatabase } from "src/ts/storage/database.svelte"
|
||||
import { getDatabase, setDatabase } from "src/ts/storage/database.svelte"
|
||||
import type { OpenAIChat } from ".."
|
||||
import { get } from "svelte/store"
|
||||
import { globalFetch } from "src/ts/storage/globalApi"
|
||||
import { alertError, alertInput, alertNormal, alertWait } from "src/ts/alert"
|
||||
import { getUserName, sleep } from "src/ts/util"
|
||||
|
||||
export function stringlizeNAIChat(formated:OpenAIChat[], char:string, continued: boolean){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
let seperator = db.NAIsettings.seperator.replaceAll("\\n","\n") || '\n'
|
||||
let starter = db.NAIsettings.starter.replaceAll("\\n","\n") || '⁂'
|
||||
let resultString:string[] = []
|
||||
@@ -109,7 +108,7 @@ export const novelLogin = async () => {
|
||||
|
||||
const data = r.data?.accessToken
|
||||
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
db.novelai.token = data
|
||||
|
||||
alertNormal('Logged in to NovelAI')
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { language } from "src/lang"
|
||||
import { alertConfirm, alertError, alertModuleSelect, alertNormal, alertStore } from "../alert"
|
||||
import { DataBase, getCurrentCharacter, getCurrentChat, setCurrentCharacter, setDatabase, type customscript, type loreBook, type triggerscript } from "../storage/database.svelte"
|
||||
import { getCurrentCharacter, getCurrentChat, getDatabase, setCurrentCharacter, setDatabase, type customscript, type loreBook, type triggerscript } from "../storage/database.svelte"
|
||||
import { AppendableBuffer, downloadFile, isNodeServer, isTauri, readImage, saveAsset } from "../storage/globalApi"
|
||||
import { get } from "svelte/store"
|
||||
import { selectSingleFile, sleep } from "../util"
|
||||
import { v4 } from "uuid"
|
||||
import { convertExternalLorebook } from "./lorebook"
|
||||
@@ -171,7 +170,7 @@ export async function importModule(){
|
||||
return
|
||||
}
|
||||
let fileData = f.data
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
if(f.name.endsWith('.risum')){
|
||||
try {
|
||||
const buf = Buffer.from(fileData)
|
||||
@@ -248,7 +247,7 @@ export async function importModule(){
|
||||
}
|
||||
|
||||
function getModuleById(id:string){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
for(let i=0;i<db.modules.length;i++){
|
||||
if(db.modules[i].id === id){
|
||||
return db.modules[i]
|
||||
@@ -259,7 +258,7 @@ function getModuleById(id:string){
|
||||
|
||||
function getModuleByIds(ids:string[]){
|
||||
let modules:RisuModule[] = []
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
for(let i=0;i<ids.length;i++){
|
||||
const module = db.modules.find((m) => m.id === ids[i] || (m.namespace === ids[i] && m.namespace))
|
||||
if(module){
|
||||
@@ -273,7 +272,7 @@ let lastModules = ''
|
||||
let lastModuleData:RisuModule[] = []
|
||||
export function getModules(){
|
||||
const currentChat = getCurrentChat()
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
let ids = db.enabledModules ?? []
|
||||
if (currentChat){
|
||||
ids = ids.concat(currentChat.modules ?? [])
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { get } from "svelte/store";
|
||||
import { tokenizeAccurate } from "../tokenizer";
|
||||
import { DataBase, presetTemplate, setDatabase, type Database } from "../storage/database.svelte";
|
||||
import { getDatabase, presetTemplate, setDatabase, type Database } from "../storage/database.svelte";
|
||||
import { alertError, alertNormal } from "../alert";
|
||||
import type { OobaChatCompletionRequestParams } from "../model/ooba";
|
||||
|
||||
@@ -383,7 +383,7 @@ export function promptConvertion(files:{ name: string, content: string, type:str
|
||||
if(type === 'STCHAT'){
|
||||
preset.aiModel = 'openrouter'
|
||||
preset.subModel = 'openrouter'
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
db.botPresets.push(preset)
|
||||
setDatabase(db)
|
||||
|
||||
@@ -461,7 +461,7 @@ export function promptConvertion(files:{ name: string, content: string, type:str
|
||||
preset.name ||= 'Converted from JSON'
|
||||
|
||||
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
db.botPresets.push(preset)
|
||||
setDatabase(db)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { get } from "svelte/store";
|
||||
import type { MultiModal, OpenAIChat, OpenAIChatFull } from ".";
|
||||
import { DataBase, type character } from "../storage/database.svelte";
|
||||
import { getDatabase, type character } from "../storage/database.svelte";
|
||||
import { pluginProcess } from "../plugins/plugins";
|
||||
import { language } from "../../lang";
|
||||
import { stringlizeAINChat, stringlizeChat, getStopStrings, unstringlizeAIN, unstringlizeChat } from "./stringlize";
|
||||
@@ -88,7 +88,7 @@ type ParameterMap = {
|
||||
};
|
||||
|
||||
function applyParameters(data: { [key: string]: any }, parameters: Parameter[], rename: ParameterMap = {}) {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
for(const parameter of parameters){
|
||||
let value = 0
|
||||
switch(parameter){
|
||||
@@ -136,7 +136,7 @@ function applyParameters(data: { [key: string]: any }, parameters: Parameter[],
|
||||
}
|
||||
|
||||
export async function requestChatData(arg:requestDataArgument, model:'model'|'submodel', abortSignal:AbortSignal=null):Promise<requestDataResponse> {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
let trys = 0
|
||||
while(true){
|
||||
const da = await requestChatDataMain(arg, model, abortSignal)
|
||||
@@ -178,7 +178,7 @@ export interface OpenAIChatExtra {
|
||||
|
||||
|
||||
export async function requestChatDataMain(arg:requestDataArgument, model:'model'|'submodel', abortSignal:AbortSignal=null):Promise<requestDataResponse> {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
let formated = structuredClone(arg.formated)
|
||||
let maxTokens = arg.maxTokens ??db.maxResponse
|
||||
let temperature = arg.temperature ?? (db.temperature / 100)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { get } from "svelte/store";
|
||||
import { CharEmotion, selectedCharID } from "../stores";
|
||||
import { DataBase, setDatabase, type character, type customscript, type groupChat, type Database } from "../storage/database.svelte";
|
||||
import { type character, type customscript, type groupChat, type Database, getDatabase } from "../storage/database.svelte";
|
||||
import { downloadFile } from "../storage/globalApi";
|
||||
import { alertError, alertNormal } from "../alert";
|
||||
import { language } from "src/lang";
|
||||
@@ -27,7 +27,7 @@ export async function processScript(char:character|groupChat, data:string, mode:
|
||||
}
|
||||
|
||||
export function exportRegex(s?:customscript[]){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
const script = s ?? db.globalscript
|
||||
const data = Buffer.from(JSON.stringify({
|
||||
type: 'regex',
|
||||
@@ -43,7 +43,7 @@ export async function importRegex(o?:customscript[]):Promise<customscript[]>{
|
||||
if(!filedata){
|
||||
return o
|
||||
}
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
try {
|
||||
const imported= JSON.parse(Buffer.from(filedata).toString('utf-8'))
|
||||
if(imported.type === 'regex' && imported.data){
|
||||
@@ -67,7 +67,7 @@ export async function importRegex(o?:customscript[]):Promise<customscript[]>{
|
||||
let bestMatchCache = new Map<string, string>()
|
||||
|
||||
export async function processScriptFull(char:character|groupChat|simpleCharacterArgument, data:string, mode:ScriptMode, chatID = -1, cbsConditions:CbsConditions = {}){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
let emoChanged = false
|
||||
const scripts = (db.globalscript ?? []).concat(char.customscript).concat(getModuleRegexScripts())
|
||||
data = await runCharacterJS({
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { get } from "svelte/store"
|
||||
import { DataBase, type character } from "../storage/database.svelte"
|
||||
import { getDatabase, type character } from "../storage/database.svelte"
|
||||
import { requestChatData } from "./request"
|
||||
import { alertError } from "../alert"
|
||||
import { globalFetch, readImage } from "../storage/globalApi"
|
||||
@@ -8,7 +8,7 @@ import type { OpenAIChat } from "."
|
||||
import { processZip } from "./processzip"
|
||||
import { keiServerURL } from "../kei/kei"
|
||||
export async function stableDiff(currentChar:character,prompt:string){
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
|
||||
if(db.sdProvider === ''){
|
||||
alertError("Stable diffusion is not set in settings.")
|
||||
@@ -56,7 +56,7 @@ export async function stableDiff(currentChar:character,prompt:string){
|
||||
}
|
||||
|
||||
export async function generateAIImage(genPrompt:string, currentChar:character, neg:string, returnSdData:string):Promise<string|false>{
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
console.log(db.sdProvider)
|
||||
if(db.sdProvider === 'webui'){
|
||||
|
||||
@@ -490,7 +490,7 @@ export async function generateAIImage(genPrompt:string, currentChar:character, n
|
||||
}
|
||||
}
|
||||
if(db.sdProvider === 'kei'){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
let auth = db?.account?.token
|
||||
if(!auth){
|
||||
db.account = JSON.parse(localStorage.getItem("fallbackRisuToken"))
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { get } from "svelte/store";
|
||||
import type { OpenAIChat } from ".";
|
||||
import { DataBase } from "../storage/database.svelte";
|
||||
import { getDatabase } from "../storage/database.svelte";
|
||||
import { getUserName } from "../util";
|
||||
|
||||
export function multiChatReplacer(){
|
||||
@@ -41,7 +40,7 @@ function appendWhitespace(prefix:string, seperator:string=" ") {
|
||||
return prefix
|
||||
}
|
||||
export function stringlizeChatOba(formated:OpenAIChat[], characterName:string, suggesting:boolean, continued:boolean){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
let resultString:string[] = []
|
||||
let { systemPrefix, userPrefix, assistantPrefix, seperator } = db.ooba.formating;
|
||||
systemPrefix = systemPrefix ?? ""
|
||||
@@ -103,7 +102,7 @@ function toTitleCase(s:string){
|
||||
return s[0].toUpperCase() + s.slice(1).toLowerCase()
|
||||
}
|
||||
export function getStopStrings(suggesting:boolean=false){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
let { userPrefix, seperator } = db.ooba.formating;
|
||||
if(!seperator){
|
||||
seperator = "\n"
|
||||
@@ -160,7 +159,7 @@ export function unstringlizeChat(text:string, formated:OpenAIChat[], char:string
|
||||
export function getUnstringlizerChunks(formated:OpenAIChat[], char:string, mode:'ain'|'normal' = 'normal'){
|
||||
let chunks:string[] = ["system note:", "system:","system note:", "system:"]
|
||||
let charNames:string[] = []
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
if(char){
|
||||
charNames.push(char)
|
||||
if(mode === 'ain'){
|
||||
@@ -212,7 +211,7 @@ export function getUnstringlizerChunks(formated:OpenAIChat[], char:string, mode:
|
||||
|
||||
export function stringlizeAINChat(formated:OpenAIChat[], char:string, continued: boolean){
|
||||
let resultString:string[] = []
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
|
||||
for(const form of formated){
|
||||
console.log(form)
|
||||
@@ -292,7 +291,7 @@ function extractAINOutputStrings(inputString:string, characters:string[]) {
|
||||
|
||||
export function unstringlizeAIN(data:string,formated:OpenAIChat[], char:string = ''){
|
||||
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const chunksResult = getUnstringlizerChunks(formated, char ,'ain')
|
||||
const chunks = chunksResult.chunks
|
||||
let result:['char'|'user',string][] = []
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Template } from '@huggingface/jinja';
|
||||
import type { OpenAIChat } from '..';
|
||||
import { get } from 'svelte/store';
|
||||
import { DataBase, getCurrentCharacter } from 'src/ts/storage/database.svelte';
|
||||
import { getCurrentCharacter, getDatabase } from 'src/ts/storage/database.svelte';
|
||||
import { getUserName } from 'src/ts/util';
|
||||
|
||||
export const chatTemplates = {
|
||||
@@ -29,7 +28,7 @@ export const applyChatTemplate = (messages:OpenAIChat[], arg:{
|
||||
type?: string
|
||||
custom?: string
|
||||
} = {}) => {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const currentChar = getCurrentCharacter()
|
||||
const type = arg.type ?? db.instructChatTemplate
|
||||
if(!type){
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { DataBase, setPreset, type botPreset, setDatabase } from "src/ts/storage/database.svelte";
|
||||
import { setPreset, type botPreset, setDatabase, getDatabase } from "src/ts/storage/database.svelte";
|
||||
import { defaultAutoSuggestPrefixOoba, defaultAutoSuggestPrompt, defaultAutoSuggestPromptOoba } from "src/ts/storage/defaultPrompts";
|
||||
import { get } from "svelte/store";
|
||||
import { prebuiltNAIpresets, prebuiltPresets } from "./templates";
|
||||
import { prebuiltPresets } from "./templates";
|
||||
import { alertConfirm, alertSelect } from "src/ts/alert";
|
||||
import { language } from "src/lang";
|
||||
|
||||
export async function setRecommended(model: string, ask:'ask'|'force') {
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
if(!(recommendedPresetExist(model))){
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { risuChatParser } from "src/ts/parser"
|
||||
import { DataBase } from "src/ts/storage/database.svelte"
|
||||
import { get } from "svelte/store"
|
||||
import { getDatabase } from "src/ts/storage/database.svelte"
|
||||
|
||||
export function convertInterfaceToSchema(int:string){
|
||||
if(!int.startsWith('interface ') && !int.startsWith('export interface ')){
|
||||
@@ -122,7 +121,7 @@ export function convertInterfaceToSchema(int:string){
|
||||
}
|
||||
|
||||
export function getOpenAIJSONSchema(){
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const schema = {
|
||||
"name": "format",
|
||||
"strict": db.strictJsonSchema,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { parseChatML, risuChatParser } from "../parser";
|
||||
import { DataBase, getCurrentCharacter, getCurrentChat, type Chat, type character } from "../storage/database.svelte";
|
||||
import { getCurrentCharacter, getCurrentChat, getDatabase, type Chat, type character } from "../storage/database.svelte";
|
||||
import { tokenize } from "../tokenizer";
|
||||
import { getModuleTriggers } from "./modules";
|
||||
import { get } from "svelte/store";
|
||||
@@ -167,7 +167,7 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{
|
||||
v.lowLevelAccess = CharacterlowLevelAccess
|
||||
return v
|
||||
}).concat(getModuleTriggers())
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
const defaultVariables = parseKeyValue(char.defaultVariables).concat(parseKeyValue(db.templateDefaultVariables))
|
||||
let chat = structuredClone(arg.chat ?? char.chats[char.chatPage])
|
||||
if((!triggers) || (triggers.length === 0)){
|
||||
@@ -191,7 +191,7 @@ export async function runTrigger(char:character,mode:triggerMode, arg:{
|
||||
function setVar(key:string, value:string){
|
||||
const selectedCharId = get(selectedCharID)
|
||||
const currentCharacter = getCurrentCharacter()
|
||||
const db = get(DataBase)
|
||||
const db = getDatabase()
|
||||
varChanged = true
|
||||
chat.scriptstate ??= {}
|
||||
chat.scriptstate['$' + key] = value
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { get } from "svelte/store";
|
||||
import { alertError } from "../alert";
|
||||
import { DataBase, getCurrentCharacter, type character } from "../storage/database.svelte";
|
||||
import { getCurrentCharacter, getDatabase, type character } from "../storage/database.svelte";
|
||||
import { runTranslator, translateVox } from "../translator/translator";
|
||||
import { globalFetch, loadAsset } from "../storage/globalApi";
|
||||
import { language } from "src/lang";
|
||||
import { sleep } from "../util";
|
||||
import { registerOnnxModel, runVITS } from "./transformers";
|
||||
import { runVITS } from "./transformers";
|
||||
|
||||
let sourceNode:AudioBufferSourceNode = null
|
||||
|
||||
@@ -23,7 +22,7 @@ export async function sayTTS(character:character,text:string) {
|
||||
return
|
||||
}
|
||||
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
text = text.replace(/\*/g,'')
|
||||
|
||||
if(character.ttsReadOnlyQuoted){
|
||||
@@ -383,7 +382,7 @@ export function getWebSpeechTTSVoices() {
|
||||
}
|
||||
|
||||
export async function getElevenTTSVoices() {
|
||||
let db = get(DataBase)
|
||||
let db = getDatabase()
|
||||
|
||||
const data = await fetch('https://api.elevenlabs.io/v1/voices', {
|
||||
headers: {
|
||||
@@ -397,7 +396,7 @@ export async function getElevenTTSVoices() {
|
||||
}
|
||||
|
||||
export async function getVOICEVOXVoices() {
|
||||
const db = get(DataBase);
|
||||
const db = getDatabase();
|
||||
const speakerData = await fetch(`${db.voicevoxUrl}/speakers`)
|
||||
const speakerList = await speakerData.json()
|
||||
const speakersInfo = speakerList.map((speaker) => {
|
||||
|
||||
Reference in New Issue
Block a user