diff --git a/src/lib/SideBars/DevTool.svelte b/src/lib/SideBars/DevTool.svelte index 3f995e22..91f4ab48 100644 --- a/src/lib/SideBars/DevTool.svelte +++ b/src/lib/SideBars/DevTool.svelte @@ -9,12 +9,81 @@ import { getCharToken, getChatToken } from "src/ts/tokenizer"; import { tokenizePreset } from "src/ts/process/prompt"; import { DataBase, setDatabase } from "src/ts/storage/database"; - import TextAreaInput from "../UI/GUI/TextAreaInput.svelte"; - import { FolderUpIcon, PlusIcon, TrashIcon } from "lucide-svelte"; - import { selectSingleFile } from "src/ts/util"; - import { file } from "jszip"; - import { doingChat, previewFormated, sendChat } from "src/ts/process"; + import TextAreaInput from "../UI/GUI/TextAreaInput.svelte"; + import { FolderUpIcon, PlusIcon, TrashIcon } from "lucide-svelte"; + import { selectSingleFile } from "src/ts/util"; + import { file } from "jszip"; + import { doingChat, previewFormated, sendChat } from "src/ts/process"; + import SelectInput from "../UI/GUI/SelectInput.svelte"; + import { applyChatTemplate, chatTemplates } from "src/ts/process/templates/chatTemplate"; + import OptionInput from "../UI/GUI/OptionInput.svelte"; + let previewMode = 'chat' + let previewJoin = 'yes' + let instructType = 'chatml' + let instructCustom = '' + + const preview = async () => { + if($doingChat){ + return false + } + alertWait("Loading...") + await sendChat(-1, { + preview: true + }) + + let md = '' + const styledRole = { + "function": "📐 Function", + "user": "😐 User", + "system": "⚙️ System", + "assistant": "✨ Assistant", + } + let formated = structuredClone(previewFormated) + + if(previewJoin === 'yes'){ + let newFormated = [] + let latestRole = '' + + for(let i=0;i 0){ + md += `> ${modals.length} non-text content(s) included\n` + } + + md += '```\n' + formated[i].content.replaceAll('```', '\\`\\`\\`') + '\n```\n' + } + $doingChat = false + alertMd(md) + } let autopilot = [] @@ -149,37 +218,34 @@ }}>Run + + + Type + + Chat + Instruct + + {#if previewMode === 'instruct'} + Instruction Type + + {#each Object.keys(chatTemplates) as template} + {template} + {/each} + Custom Jinja + + {#if instructType === 'jinja'} + Custom Jinja + + {/if} + {/if} + Join + + With Join + Without Join + + + + - - \ No newline at end of file +}}>Request Log \ No newline at end of file diff --git a/src/ts/process/templates/chatTemplate.ts b/src/ts/process/templates/chatTemplate.ts index a12886bd..f1ff328d 100644 --- a/src/ts/process/templates/chatTemplate.ts +++ b/src/ts/process/templates/chatTemplate.ts @@ -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