Improve preview prompt

This commit is contained in:
kwaroran
2024-09-08 23:40:45 +09:00
parent dda2359630
commit e334551976
2 changed files with 109 additions and 40 deletions

View File

@@ -26,15 +26,18 @@ export const templateEffect = {
],
} as {[key:string]:TemplateEffect[]}
export const applyChatTemplate = (messages:OpenAIChat[]) => {
export const applyChatTemplate = (messages:OpenAIChat[], arg:{
type?: string
custom?: string
} = {}) => {
const db = get(DataBase)
const currentChar = get(CurrentCharacter)
const type = db.instructChatTemplate
const type = arg.type ?? db.instructChatTemplate
if(!type){
throw new Error('Template type is not set')
}
let clonedMessages = structuredClone(messages)
const template = type === 'jinja' ? (new Template(db.JinjaTemplate)) :(new Template(chatTemplates[type]))
const template = type === 'jinja' ? (new Template(arg.custom ?? db.JinjaTemplate)) :(new Template(chatTemplates[type]))
let formatedMessages:{
"role": 'user'|'assistant'|'system',
"content": string