Fixed the problem that auto-suggestion does not work for firstMessage
Fixed the problem that auto-suggestion is not saved
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { requestChatData } from "src/ts/process/request";
|
import { requestChatData } from "src/ts/process/request";
|
||||||
import { doingChat, type OpenAIChat } from "../../ts/process/index";
|
import { doingChat, type OpenAIChat } from "../../ts/process/index";
|
||||||
import { DataBase, type character } from "../../ts/storage/database";
|
import { DataBase, setDatabase, type character, type Message, type groupChat, type Database } from "../../ts/storage/database";
|
||||||
import { selectedCharID } from "../../ts/stores";
|
import { selectedCharID } from "../../ts/stores";
|
||||||
import { translate } from "src/ts/translator/translator";
|
import { translate } from "src/ts/translator/translator";
|
||||||
import { CopyIcon, LanguagesIcon, RefreshCcwIcon } from "lucide-svelte";
|
import { CopyIcon, LanguagesIcon, RefreshCcwIcon } from "lucide-svelte";
|
||||||
@@ -9,12 +9,14 @@
|
|||||||
import { language } from "src/lang";
|
import { language } from "src/lang";
|
||||||
import { replacePlaceholders } from "../../ts/util";
|
import { replacePlaceholders } from "../../ts/util";
|
||||||
import { onDestroy } from 'svelte';
|
import { onDestroy } from 'svelte';
|
||||||
|
import { processScript } from "src/ts/process/scripts";
|
||||||
|
import { get } from "svelte/store";
|
||||||
|
|
||||||
export let send: () => any;
|
export let send: () => any;
|
||||||
export let messageInput:(string:string) => any;
|
export let messageInput:(string:string) => any;
|
||||||
let suggestMessages = $DataBase.characters[$selectedCharID]?.chats[$DataBase.characters[$selectedCharID].chatPage]?.suggestMessages
|
let suggestMessages:string[] = $DataBase.characters[$selectedCharID]?.chats[$DataBase.characters[$selectedCharID].chatPage]?.suggestMessages
|
||||||
let suggestMessagesTranslated:string[]
|
let suggestMessagesTranslated:string[]
|
||||||
let toggleTranslate = $DataBase.autoTranslate
|
let toggleTranslate:boolean = $DataBase.autoTranslate
|
||||||
let progress:boolean;
|
let progress:boolean;
|
||||||
let progressChatPage=-1;
|
let progressChatPage=-1;
|
||||||
let abortController:AbortController;
|
let abortController:AbortController;
|
||||||
@@ -45,9 +47,20 @@
|
|||||||
suggestMessages = []
|
suggestMessages = []
|
||||||
}
|
}
|
||||||
if(!v && $selectedCharID > -1 && (!suggestMessages || suggestMessages.length === 0) && !progress){
|
if(!v && $selectedCharID > -1 && (!suggestMessages || suggestMessages.length === 0) && !progress){
|
||||||
let currentChar = $DataBase.characters[$selectedCharID] as character;
|
let currentChar:character|groupChat = $DataBase.characters[$selectedCharID];
|
||||||
let messages = currentChar.chats[currentChar.chatPage].message;
|
let messages:Message[] = []
|
||||||
let lastMessages = messages.slice(Math.max(messages.length - 10, 0));
|
|
||||||
|
if(currentChar.type !== 'group'){
|
||||||
|
const firstMsg:string = currentChar.firstMsgIndex === -1 ? currentChar.firstMessage : currentChar.alternateGreetings[currentChar.firstMsgIndex]
|
||||||
|
messages.push({
|
||||||
|
role: 'char',
|
||||||
|
data: processScript(currentChar,
|
||||||
|
replacePlaceholders(firstMsg, currentChar.name),
|
||||||
|
'editprocess')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
messages = [...messages, ...currentChar.chats[currentChar.chatPage].message];
|
||||||
|
let lastMessages:Message[] = messages.slice(Math.max(messages.length - 10, 0));
|
||||||
if(lastMessages.length === 0)
|
if(lastMessages.length === 0)
|
||||||
return
|
return
|
||||||
const promptbody:OpenAIChat[] = [
|
const promptbody:OpenAIChat[] = [
|
||||||
@@ -58,7 +71,7 @@
|
|||||||
,
|
,
|
||||||
{
|
{
|
||||||
role: 'user',
|
role: 'user',
|
||||||
content: lastMessages.map(b=>b.role+":"+b.data).reduce((a,b)=>a+','+b)
|
content: lastMessages.map(b=>(b.role==='char'? 'assistant' : 'user')+":"+b.data).reduce((a,b)=>a+','+b)
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -68,11 +81,13 @@
|
|||||||
requestChatData({
|
requestChatData({
|
||||||
formated: promptbody,
|
formated: promptbody,
|
||||||
bias: {},
|
bias: {},
|
||||||
currentChar
|
currentChar : currentChar as character
|
||||||
}, 'submodel', abortController.signal).then(rq2=>{
|
}, 'submodel', abortController.signal).then(rq2=>{
|
||||||
if(rq2.type !== 'fail' && rq2.type !== 'streaming' && progress){
|
if(rq2.type !== 'fail' && rq2.type !== 'streaming' && progress){
|
||||||
var suggestMessagesNew = rq2.result.split('\n').filter(msg => msg.startsWith('-')).map(msg => msg.replace('-','').trim())
|
var suggestMessagesNew = rq2.result.split('\n').filter(msg => msg.startsWith('-')).map(msg => msg.replace('-','').trim())
|
||||||
currentChar.chats[currentChar.chatPage].suggestMessages = suggestMessagesNew
|
const db:Database = get(DataBase);
|
||||||
|
db.characters[$selectedCharID].chats[currentChar.chatPage].suggestMessages = suggestMessagesNew
|
||||||
|
setDatabase(db)
|
||||||
suggestMessages = suggestMessagesNew
|
suggestMessages = suggestMessagesNew
|
||||||
}
|
}
|
||||||
progress = false
|
progress = false
|
||||||
|
|||||||
Reference in New Issue
Block a user