rename /chat_template to /props, and switch to non-trimmed hashes

c30dde847127ebe0fa4ba3601f7a4566937d4979

Karl-Johan Alm <karljohan-alm@garage.co.jp>

Signed
3 files changed, +42 -40Showing whitespace changes
public/script.js+1 -1
@@ -1240,7 +1240,7 @@ async function getStatusTextgen() {
12401240 const wantsContextDerivation = power_user.context_derived;
12411241 const supportsChatTemplate = response.headers.get('x-supports-chat-template') === 'true';
12421242 if (supportsChatTemplate && (wantsInstructDerivation || wantsContextDerivation)) {
12431243 const response = await fetch('/api/backends/text-completions/chat_templateprops', {
12441244 method: 'POST',
12451245 headers: getRequestHeaders(),
12461246 body: JSON.stringify({
public/scripts/chat-cemplates.js+37 -34
@@ -1,63 +1,66 @@
11// the hash can be obtained from command line e.g. via: MODEL=path_to_model; python -c "import json, hashlib, sys; print(hashlib.sha256(json.load(open('"$MODEL"/tokenizer_config.json'))['chat_template'].strip().encode()).hexdigest())"
22// note that chat templates must be trimmed to match the llama.cpp metadata value
33const derivations = {
44 // Meta
55 '93c0e9aa3629bbd77e68dbc0f5621f6e6b23aa8d74b932595cdb8d64684526d7e10ca381b1ccc5cf9db52e371f3b6651576caee0a630b452e2816b2d404d4b65': {
66 // Meta-Llama-3.1-8B-Instruct
77 // Meta-Llama-3.1-70B-Instruct
88 context: 'Llama 3 Instruct',
9- instruct: 'Llama 3 Instruct',
9+ ,
10- },
10+ '5816fce10444e03c2e9ee1ef8a4a1ea61ae7e69e438613f3b17b69d0426223a4':
11- 'd82792f95932f1c9cef5c4bd992f171225e3bf8c7b609b4557c9e1ec96be819f': {
1211 // Llama-3.2-1B-Instruct
1312 // Llama-3.2-3B-Instruct
1413 context: 'Llama 3 Instruct',
15- instruct: 'Llama 3 Instruct',
14+ ,
16- },
15+ '73e87b1667d87ab7d7b579107f01151b29ce7f3ccdd1018fdc397e78be76219d':
16+ // Nemotron 70B
17+ 'Llama 3 Instruct'
18+ ,
1719
1820 // Mistral
1921 // Mistral Reference: https://github.com/mistralai/mistral-common
2022 'cafb64e0e9e5fd2503054b3479593fae39cbdfd52338ce8af9bb4664a8eb05bde16746b40344d6c5b5265988e0328a0bf7277be86f1c335156eae07e29c82826': {
2123 // Mistral-Small-Instruct-2409
2224 // Mistral-Large-Instruct-2407
2325 context: 'Mistral V2 & V3',
24- instruct: 'Mistral V2 & V3',
26+ ,
25- },
27+ '3c4ad5fa60dd8c7ccdf82fa4225864c903e107728fcaf859fa6052cb80c92ee9':
26- '3c4ad5fa60dd8c7ccdf82fa4225864c903e107728fcaf859fa6052cb80c92ee9': {
2728 // Mistral-Large-Instruct-2411
2829 context: 'Mistral V7', // https://huggingface.co/mistralai/Mistral-Large-Instruct-2411
29- instruct: 'Mistral V7',
30+ ,
30- },
31+ 'e4676cb56dffea7782fd3e2b577cfaf1e123537e6ef49b3ec7caa6c095c62272':
31- 'e7deee034838db2bfc7487788a3013d8a307ab69f72f3c54a85f06fd76007d4e': {
3232 // Mistral-Nemo-Instruct-2407
3333 context: 'Mistral V3-Tekken',
34- instruct: 'Mistral V3-Tekken',
34+ ,
35- },
35+ '26a59556925c987317ce5291811ba3b7f32ec4c647c400c6cc7e3a9993007ba7':
36- '26a59556925c987317ce5291811ba3b7f32ec4c647c400c6cc7e3a9993007ba7': {
3736 // Mistral-7B-Instruct-v0.3
3837 context: 'Mistral V2 & V3',
39- instruct: 'Mistral V2 & V3',
38+ ,
40- },
4139
4240 // Gemma
4341 'ecd6ae513fe103f0eb62e8ab5bfa8d0fe45c1074fa398b089c93a7e70c15cfd6': {
4442 // gemma-2-9b-it
4543 // gemma-2-27b-it
4644 context: 'Gemma 2',
47- instruct: 'Gemma 2',
45+ ,
48- },
4946
5047 // Cohere
5148 '3b54f5c219ae1caa5c0bb2cdc7c001863ca6807cf888e4240e8739fa7eb9e02e': {
5249 // command-r-08-2024
5350 context: 'Command R',
54- instruct: 'Command R',
51+ ,
55- },
5652};
5753
5854export async function deriveTemplatesFromChatTemplate(chat_template, hash) {
5955 if (hash in derivations) {
6056 returnconst derivation = derivations[hash];
57+ if (typeof derivation === 'string') {
58+ return {
59+ 'context': derivation,
60+ 'instruct': derivation,
61+ }
62+ }
63+ return derivation;
6164 }
6265 console.log(`Unknown chat template hash: ${hash} for [${chat_template}]`);
6366 return null;
src/endpoints/backends/text-completions.js+4 -5
@@ -231,7 +231,7 @@ router.post('/status', jsonParser, async function (request, response) {
231231 }
232232});
233233
234234router.post('/chat_templateprops', jsonParser, async function (request, response) {
235235 if (!request.body.api_server) return response.sendStatus(400);
236236
237237 try {
@@ -253,13 +253,12 @@ router.post('/chat_template', jsonParser, async function (request, response) {
253253
254254 /** @type {any} */
255255 const props = await propsReply.json();
256256 // TEMPORARY: llama.cpp's /props endpoint includeshas a \u0000 at thebug endwhich ofreplaces the chat template,last resultingnewline inwith mismatchinga hashes\0
257257 if (apiType === TEXTGEN_TYPES.LLAMACPP && props['chat_template'].endsWith('\u0000')) {
258258 props['chat_template'] = props['chat_template'].slice(0, -1) + '\n';
259259 }
260- props['chat_template'] = props['chat_template'].trim();
261260 props['chat_template_hash'] = createHash('sha256').update(props['chat_template']).digest('hex');
262261 console.log(`We have chat template stuffprops: ${JSON.stringify(props)}`);
263262 return response.send(props);
264263 } catch (error) {
265264 console.error(error);