Add Saving Icon
This commit is contained in:
@@ -302,6 +302,9 @@ export async function loadAsset(id:string){
|
||||
}
|
||||
|
||||
let lastSave = ''
|
||||
export let saving = $state({
|
||||
state: false
|
||||
})
|
||||
|
||||
/**
|
||||
* Saves the current state of the database.
|
||||
@@ -335,19 +338,25 @@ export async function saveDb(){
|
||||
$effect.root(() => {
|
||||
|
||||
let selIdState = $state(0)
|
||||
let oldSaveHash = ''
|
||||
|
||||
selectedCharID.subscribe((v) => {
|
||||
selIdState = v
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
$state.snapshot(DBState?.db?.characters?.[selIdState])
|
||||
let newSaveHash = ''
|
||||
newSaveHash += JSON.stringify(DBState?.db?.characters?.[selIdState])
|
||||
for(const key in DBState.db){
|
||||
if(key !== 'characters'){
|
||||
$state.snapshot(DBState.db[key])
|
||||
newSaveHash += (DBState.db[key])
|
||||
}
|
||||
}
|
||||
changed = true
|
||||
|
||||
if(newSaveHash !== oldSaveHash){
|
||||
changed = true
|
||||
oldSaveHash = newSaveHash
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -356,10 +365,11 @@ export async function saveDb(){
|
||||
await sleep(1000)
|
||||
while(true){
|
||||
if(!changed){
|
||||
await sleep(1000)
|
||||
await sleep(500)
|
||||
continue
|
||||
}
|
||||
|
||||
saving.state = true
|
||||
changed = false
|
||||
|
||||
try {
|
||||
@@ -430,6 +440,8 @@ export async function saveDb(){
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
saving.state = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1392,60 +1392,68 @@ async function requestOoba(arg:RequestDataArgumentExtended):Promise<requestDataR
|
||||
}
|
||||
|
||||
async function requestPlugin(arg:RequestDataArgumentExtended):Promise<requestDataResponse> {
|
||||
const formated = arg.formated
|
||||
const db = getDatabase()
|
||||
const maxTokens = arg.maxTokens
|
||||
const bias = arg.biasString
|
||||
const v2Function = pluginV2.providers.get(db.currentPluginProvider)
|
||||
|
||||
const d = v2Function ? (await v2Function(applyParameters({
|
||||
prompt_chat: formated,
|
||||
mode: arg.mode,
|
||||
bias: []
|
||||
}, [
|
||||
'frequency_penalty','min_p','presence_penalty','repetition_penalty','top_k','top_p','temperature'
|
||||
], {}, arg.mode) as any)) : await pluginProcess({
|
||||
bias: bias,
|
||||
prompt_chat: formated,
|
||||
temperature: (db.temperature / 100),
|
||||
max_tokens: maxTokens,
|
||||
presence_penalty: (db.PresensePenalty / 100),
|
||||
frequency_penalty: (db.frequencyPenalty / 100)
|
||||
})
|
||||
|
||||
if(!d){
|
||||
return {
|
||||
type: 'fail',
|
||||
result: (language.errors.unknownModel)
|
||||
}
|
||||
}
|
||||
else if(!d.success){
|
||||
return {
|
||||
type: 'fail',
|
||||
result: d.content instanceof ReadableStream ? await (new Response(d.content)).text() : d.content
|
||||
}
|
||||
}
|
||||
else if(d.content instanceof ReadableStream){
|
||||
|
||||
let fullText = ''
|
||||
const piper = new TransformStream<string, StreamResponseChunk>( {
|
||||
transform(chunk, control) {
|
||||
fullText += chunk
|
||||
control.enqueue({
|
||||
"0": fullText
|
||||
})
|
||||
}
|
||||
try {
|
||||
const formated = arg.formated
|
||||
const maxTokens = arg.maxTokens
|
||||
const bias = arg.biasString
|
||||
const v2Function = pluginV2.providers.get(db.currentPluginProvider)
|
||||
|
||||
const d = v2Function ? (await v2Function(applyParameters({
|
||||
prompt_chat: formated,
|
||||
mode: arg.mode,
|
||||
bias: []
|
||||
}, [
|
||||
'frequency_penalty','min_p','presence_penalty','repetition_penalty','top_k','top_p','temperature'
|
||||
], {}, arg.mode) as any)) : await pluginProcess({
|
||||
bias: bias,
|
||||
prompt_chat: formated,
|
||||
temperature: (db.temperature / 100),
|
||||
max_tokens: maxTokens,
|
||||
presence_penalty: (db.PresensePenalty / 100),
|
||||
frequency_penalty: (db.frequencyPenalty / 100)
|
||||
})
|
||||
|
||||
return {
|
||||
type: 'streaming',
|
||||
result: d.content.pipeThrough(piper)
|
||||
|
||||
if(!d){
|
||||
return {
|
||||
type: 'fail',
|
||||
result: (language.errors.unknownModel)
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
else if(!d.success){
|
||||
return {
|
||||
type: 'fail',
|
||||
result: d.content instanceof ReadableStream ? await (new Response(d.content)).text() : d.content
|
||||
}
|
||||
}
|
||||
else if(d.content instanceof ReadableStream){
|
||||
|
||||
let fullText = ''
|
||||
const piper = new TransformStream<string, StreamResponseChunk>( {
|
||||
transform(chunk, control) {
|
||||
fullText += chunk
|
||||
control.enqueue({
|
||||
"0": fullText
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
return {
|
||||
type: 'streaming',
|
||||
result: d.content.pipeThrough(piper)
|
||||
}
|
||||
}
|
||||
else{
|
||||
return {
|
||||
type: 'success',
|
||||
result: d.content
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
return {
|
||||
type: 'success',
|
||||
result: d.content
|
||||
type: 'fail',
|
||||
result: `Plugin Error from ${db.currentPluginProvider}: ` + JSON.stringify(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -462,6 +462,7 @@ export function setDatabase(data:Database){
|
||||
data.customFlags ??= []
|
||||
data.enableCustomFlags ??= false
|
||||
data.assetMaxDifference ??= 4
|
||||
data.showSavingIcon ??= false
|
||||
changeLanguage(data.language)
|
||||
setDatabaseLite(data)
|
||||
}
|
||||
@@ -858,6 +859,7 @@ export interface Database{
|
||||
assetMaxDifference:number
|
||||
menuSideBar:boolean
|
||||
pluginV2: RisuPlugin[]
|
||||
showSavingIcon:boolean
|
||||
}
|
||||
|
||||
interface SeparateParameters{
|
||||
|
||||
Reference in New Issue
Block a user