Merge 01d17ff137
into 1b26aebe4d
This commit is contained in:
commit
9c2de3b6eb
2 changed files with 47 additions and 1 deletions
16
examples/server/public/chat_templates.js
Normal file
16
examples/server/public/chat_templates.js
Normal file
|
@ -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"
|
||||||
|
}
|
||||||
|
};
|
|
@ -203,6 +203,9 @@
|
||||||
|
|
||||||
import { llama } from '/completion.js';
|
import { llama } from '/completion.js';
|
||||||
import { SchemaConverter } from '/json-schema-to-grammar.mjs';
|
import { SchemaConverter } from '/json-schema-to-grammar.mjs';
|
||||||
|
|
||||||
|
import { chat_templates } from '/chat_templates.js';
|
||||||
|
|
||||||
let selected_image = false;
|
let selected_image = false;
|
||||||
var slot_id = -1;
|
var slot_id = -1;
|
||||||
|
|
||||||
|
@ -713,6 +716,28 @@
|
||||||
</fieldset>
|
</fieldset>
|
||||||
`
|
`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const PromptTemplateOptions = () => {
|
||||||
|
var templatenames = Object.keys(chat_templates);
|
||||||
|
templatenames.sort();
|
||||||
|
var optionlist = templatenames.map(name => html`<option value="${name}">${name}</option>`);
|
||||||
|
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 = () => (
|
const ChatConfigForm = () => (
|
||||||
html`
|
html`
|
||||||
|
@ -733,12 +758,17 @@
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<div>
|
<div>
|
||||||
<label for="template">Prompt template</label>
|
<label for="template">Prompt template</label>
|
||||||
|
<select id="templateSelect" onchange=${updatePromptTemplate} >
|
||||||
|
<option value="">- Select a chat template -</option>
|
||||||
|
${PromptTemplateOptions()}
|
||||||
|
</select>
|
||||||
|
|
||||||
<textarea id="template" name="template" value="${session.value.template}" rows=4 oninput=${updateSession}/>
|
<textarea id="template" name="template" value="${session.value.template}" rows=4 oninput=${updateSession}/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label for="template">Chat history template</label>
|
<label for="template">Chat history template</label>
|
||||||
<textarea id="template" name="historyTemplate" value="${session.value.historyTemplate}" rows=1 oninput=${updateSession}/>
|
<textarea id="historyTemplate" name="historyTemplate" value="${session.value.historyTemplate}" rows=1 oninput=${updateSession}/>
|
||||||
</div>
|
</div>
|
||||||
${GrammarControl()}
|
${GrammarControl()}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue