From 2f2191fb70d87ebe235550518722750ab44bd1c0 Mon Sep 17 00:00:00 2001 From: chris Date: Sun, 4 Feb 2024 23:47:29 +0100 Subject: [PATCH] Add minimal chat template support in server UI (pull-down menu) --- examples/server/public/chat_templates.js | 16 ++++++++++++ examples/server/public/index.html | 32 +++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 examples/server/public/chat_templates.js diff --git a/examples/server/public/chat_templates.js b/examples/server/public/chat_templates.js new file mode 100644 index 000000000..821e0c987 --- /dev/null +++ b/examples/server/public/chat_templates.js @@ -0,0 +1,16 @@ +export const chat_templates = { + "Alpaca" : { + "template" : "{{prompt}}\n### Instruction:\n{{history}}\n### Response:\n{{char}}:", + "historyTemplate" : "{{name}}: {{message}}" + }, + + "Vicuna" : { + "template" : "{{prompt}}\n\n{{history}}\n{{char}}:", + "historyTemplate" : "{{name}}: {{message}}" + }, + + "ChatML" : { + "template" : "<|im_start|>system\n{{prompt}}<|im_end|>\n{{history}}<|im_start|>{{char}}\n", + "historyTemplate" : "<|im_start|>{{name}}\n{{message}}<|im_end|>\n" + } +}; diff --git a/examples/server/public/index.html b/examples/server/public/index.html index b059c75f2..9b62e5883 100644 --- a/examples/server/public/index.html +++ b/examples/server/public/index.html @@ -203,6 +203,9 @@ import { llama } from '/completion.js'; import { SchemaConverter } from '/json-schema-to-grammar.mjs'; + + import { chat_templates } from '/chat_templates.js'; + let selected_image = false; var slot_id = -1; @@ -710,6 +713,28 @@ ` ); + + const PromptTemplateOptions = () => { + var templatenames = Object.keys(chat_templates); + templatenames.sort(); + var optionlist = templatenames.map(name => html``); + return optionlist; + }; + + const updatePromptTemplate = (el) => { + // Get the selected template name + var templatename = el.target.value; + // console.log(templatename); + if (templatename != "") { + // set the template parameters + session.value.template = chat_templates[templatename]["template"]; + session.value.historyTemplate = chat_templates[templatename]["historyTemplate"]; + + // this line is required to trigger the setting of the textareas + session.value = { ...session.value, image_selected: '' }; + } + } + const ChatConfigForm = () => ( html` @@ -730,12 +755,17 @@
+ +