[feat] prompt role formater

This commit is contained in:
kwaroran
2023-06-14 23:00:13 +09:00
parent 415a8a07e4
commit 1c170ef8a7
2 changed files with 26 additions and 29 deletions

View File

@@ -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){

View File

@@ -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