[feat] better stringlizer
This commit is contained in:
@@ -18,6 +18,7 @@ export interface OpenAIChat{
|
|||||||
role: 'system'|'user'|'assistant'
|
role: 'system'|'user'|'assistant'
|
||||||
content: string
|
content: string
|
||||||
memo?:string
|
memo?:string
|
||||||
|
name?:string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const doingChat = writable(false)
|
export const doingChat = writable(false)
|
||||||
@@ -200,22 +201,26 @@ export async function sendChat(chatProcessIndex = -1):Promise<boolean> {
|
|||||||
const ms = currentChat.message
|
const ms = currentChat.message
|
||||||
for(const msg of ms){
|
for(const msg of ms){
|
||||||
let formedChat = processScript(currentChar,replacePlaceholders(msg.data, currentChar.name), 'editprocess')
|
let formedChat = processScript(currentChar,replacePlaceholders(msg.data, currentChar.name), 'editprocess')
|
||||||
if(nowChatroom.type === 'group'){
|
let name = ''
|
||||||
if(msg.saying && msg.role === 'char'){
|
if(msg.role === 'char'){
|
||||||
formedChat = `${findCharacterbyIdwithCache(msg.saying).name}: ${formedChat}`
|
if(msg.saying){
|
||||||
|
name = `${findCharacterbyIdwithCache(msg.saying).name}`
|
||||||
}
|
}
|
||||||
else if(msg.role === 'user'){
|
else{
|
||||||
formedChat = `${db.username}: ${formedChat}`
|
name = `${currentChar.name}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(msg.role === 'user'){
|
||||||
|
name = `${db.username}`
|
||||||
|
}
|
||||||
if(!msg.chatId){
|
if(!msg.chatId){
|
||||||
msg.chatId = v4()
|
msg.chatId = v4()
|
||||||
}
|
}
|
||||||
chats.push({
|
chats.push({
|
||||||
role: msg.role === 'user' ? 'user' : 'assistant',
|
role: msg.role === 'user' ? 'user' : 'assistant',
|
||||||
content: formedChat,
|
content: formedChat,
|
||||||
memo: msg.chatId
|
memo: msg.chatId,
|
||||||
|
name: name
|
||||||
})
|
})
|
||||||
currentTokens += (await tokenize(formedChat) + 1)
|
currentTokens += (await tokenize(formedChat) + 1)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,11 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model'
|
|||||||
switch(aiModel){
|
switch(aiModel){
|
||||||
case 'gpt35':
|
case 'gpt35':
|
||||||
case 'gpt4':{
|
case 'gpt4':{
|
||||||
|
|
||||||
|
for(let i=0;i<formated.length;i++){
|
||||||
|
formated[i].name = undefined
|
||||||
|
}
|
||||||
|
|
||||||
const body = ({
|
const body = ({
|
||||||
model: aiModel === 'gpt35' ? 'gpt-3.5-turbo' : 'gpt-4',
|
model: aiModel === 'gpt35' ? 'gpt-3.5-turbo' : 'gpt-4',
|
||||||
messages: formated,
|
messages: formated,
|
||||||
|
|||||||
@@ -8,13 +8,10 @@ export function stringlizeChat(formated:OpenAIChat[], char:string = ''){
|
|||||||
let resultString:string[] = []
|
let resultString:string[] = []
|
||||||
for(const form of formated){
|
for(const form of formated){
|
||||||
if(form.role === 'system'){
|
if(form.role === 'system'){
|
||||||
resultString.push("'System Note: " + form.content)
|
resultString.push("system note: " + form.content)
|
||||||
}
|
}
|
||||||
else if(form.role === 'user'){
|
else{
|
||||||
resultString.push("user: " + form.content)
|
resultString.push(form.name + ": " + form.content)
|
||||||
}
|
|
||||||
else if(form.role === 'assistant'){
|
|
||||||
resultString.push("assistant: " + form.content)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return resultString.join('\n\n') + `\n\n${char}:`
|
return resultString.join('\n\n') + `\n\n${char}:`
|
||||||
|
|||||||
Reference in New Issue
Block a user