[feat] better stringlizer
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -53,6 +53,11 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
|
||||
switch(aiModel){
|
||||
case 'gpt35':
|
||||
case 'gpt4':{
|
||||
|
||||
for(let i=0;i<formated.length;i++){
|
||||
formated[i].name = undefined
|
||||
}
|
||||
|
||||
const body = ({
|
||||
model: aiModel === 'gpt35' ? 'gpt-3.5-turbo' : 'gpt-4',
|
||||
messages: formated,
|
||||
|
||||
@@ -8,13 +8,10 @@ export function stringlizeChat(formated:OpenAIChat[], char:string = ''){
|
||||
let resultString:string[] = []
|
||||
for(const form of formated){
|
||||
if(form.role === 'system'){
|
||||
resultString.push("'System Note: " + form.content)
|
||||
resultString.push("system note: " + form.content)
|
||||
}
|
||||
else if(form.role === 'user'){
|
||||
resultString.push("user: " + form.content)
|
||||
}
|
||||
else if(form.role === 'assistant'){
|
||||
resultString.push("assistant: " + form.content)
|
||||
else{
|
||||
resultString.push(form.name + ": " + form.content)
|
||||
}
|
||||
}
|
||||
return resultString.join('\n\n') + `\n\n${char}:`
|
||||
|
||||
Reference in New Issue
Block a user