[feat] better stringlizer

This commit is contained in:
kwaroran
2023-05-24 02:39:56 +09:00
parent 53ca05652d
commit 3f4baac593
3 changed files with 20 additions and 13 deletions

View File

@@ -18,6 +18,7 @@ export interface OpenAIChat{
role: 'system'|'user'|'assistant'
content: string
memo?:string
name?:string
}
export const doingChat = writable(false)
@@ -200,22 +201,26 @@ export async function sendChat(chatProcessIndex = -1):Promise<boolean> {
const ms = currentChat.message
for(const msg of ms){
let formedChat = processScript(currentChar,replacePlaceholders(msg.data, currentChar.name), 'editprocess')
if(nowChatroom.type === 'group'){
if(msg.saying && msg.role === 'char'){
formedChat = `${findCharacterbyIdwithCache(msg.saying).name}: ${formedChat}`
let name = ''
if(msg.role === 'char'){
if(msg.saying){
name = `${findCharacterbyIdwithCache(msg.saying).name}`
}
else if(msg.role === 'user'){
formedChat = `${db.username}: ${formedChat}`
else{
name = `${currentChar.name}`
}
}
else if(msg.role === 'user'){
name = `${db.username}`
}
if(!msg.chatId){
msg.chatId = v4()
}
chats.push({
role: msg.role === 'user' ? 'user' : 'assistant',
content: formedChat,
memo: msg.chatId
memo: msg.chatId,
name: name
})
currentTokens += (await tokenize(formedChat) + 1)
}