diff --git a/src/ts/process/index.ts b/src/ts/process/index.ts index c805f683..2f0fb543 100644 --- a/src/ts/process/index.ts +++ b/src/ts/process/index.ts @@ -156,22 +156,34 @@ export async function sendChat(chatProcessIndex = -1,arg:{chatAdditonalTokens?:n if(!currentChar.utilityBot){ const mainp = currentChar.systemPrompt || db.mainPrompt - unformated.main.push({ - role: 'system', - content: replacePlaceholders(mainp + ((db.additionalPrompt === '' || (!db.promptPreprocess)) ? '' : `\n${db.additionalPrompt}`), currentChar.name) - }) + + function formatPrompt(data:string){ + if(!data.startsWith('@@@')){ + data = "@@@system\n" + data + } + const parts = data.split(/@@@(user|assistant|system)\n/); + + // Initialize empty array for the chat objects + const chatObjects: OpenAIChat[] = []; + + // Loop through the parts array two elements at a time + for (let i = 1; i < parts.length; i += 2) { + const role = parts[i] as 'user' | 'assistant' | 'system'; + const content = parts[i + 1]?.trim() || ''; + chatObjects.push({ role, content }); + } + + console.log(chatObjects) + return chatObjects; + } + + unformated.main.push(...formatPrompt(replacePlaceholders(mainp + ((db.additionalPrompt === '' || (!db.promptPreprocess)) ? '' : `\n${db.additionalPrompt}`), currentChar.name))) if(db.jailbreakToggle){ - unformated.jailbreak.push({ - role: 'system', - content: replacePlaceholders(db.jailbreak, currentChar.name) - }) + unformated.jailbreak.push(...formatPrompt(replacePlaceholders(db.jailbreak, currentChar.name))) } - unformated.globalNote.push({ - role: 'system', - content: replacePlaceholders(currentChar.replaceGlobalNote || db.globalNote, currentChar.name) - }) + unformated.globalNote.push(...formatPrompt(replacePlaceholders(currentChar.replaceGlobalNote || db.globalNote, currentChar.name))) } if(currentChat.note){ diff --git a/src/ts/process/request.ts b/src/ts/process/request.ts index f261adaf..db657bb2 100644 --- a/src/ts/process/request.ts +++ b/src/ts/process/request.ts @@ -140,9 +140,7 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model' presence_penalty: arg.PresensePenalty ?? (db.PresensePenalty / 100), frequency_penalty: arg.frequencyPenalty ?? (db.frequencyPenalty / 100), logit_bias: bias, - stream: false, - functions: oaiFunctions, - function_call: oaiFunctionCall + stream: false }) let replacerURL = replacer === '' ? 'https://api.openai.com/v1/chat/completions' : replacer @@ -232,21 +230,8 @@ export async function requestChatDataMain(arg:requestDataArgument, model:'model' const dat = res.data as any if(res.ok){ try { + console.log(dat) const msg:OpenAIChatFull = (dat.choices[0].message) - if(msg.function_call){ - console.log(msg.function_call) - const functionarg = JSON.parse(msg.function_call.arguments) - arg.formated.push({ - "role": "function", - "name": 'set_emotion', - "content": "successfuly set to " + functionarg.emotion, - }) - arg.useEmotion = false - const d = await requestChatDataMain(arg, model, abortSignal) - d.special = d.special ?? {} - d.special.emotion = functionarg.emotion - return d - } return { type: 'success', result: msg.content