Add risu_char and risu_user

This commit is contained in:
kwaroran
2024-04-25 01:01:02 +09:00
parent 4a820aac4a
commit 68571143bf

View File

@@ -2,6 +2,7 @@ import { Template } from '@huggingface/jinja';
import type { OpenAIChat } from '..';
import { get } from 'svelte/store';
import { DataBase } from 'src/ts/storage/database';
import { CurrentCharacter } from 'src/ts/stores';
export const chatTemplates = {
'llama3': "{% set bos_token = '<|begin_of_text|>' %}{% set loop_messages = messages %}{% for message in loop_messages %}{% set content = '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n'+ message['content'] | trim + '<|eot_id|>' %}{% if loop.index0 == 0 %}{% set content = bos_token + content %}{% endif %}{{ content }}{% endfor %}{{ '<|start_header_id|>assistant<|end_header_id|>\n\n' }}",
@@ -26,6 +27,7 @@ export const templateEffect = {
export const applyChatTemplate = (messages:OpenAIChat[]) => {
const db = get(DataBase)
const currentChar = get(CurrentCharacter)
const type = db.instructChatTemplate
if(!type){
throw new Error('Template type is not set')
@@ -89,6 +91,8 @@ export const applyChatTemplate = (messages:OpenAIChat[]) => {
return template.render({
"messages": formatedMessages,
"add_generation_prompt": true
"add_generation_prompt": true,
"risu_char": currentChar.name,
"risu_user": db.username
})
}