mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
added substr derivations with one example
This commit is contained in:
@@ -1252,7 +1252,7 @@ async function getStatusTextgen() {
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if (data) {
|
if (data) {
|
||||||
const { chat_template, chat_template_hash } = data;
|
const { chat_template, chat_template_hash } = data;
|
||||||
console.log(`${wantsContextDerivation} ${wantsInstructDerivation} We have chat template ${chat_template.split('\n')[0]}...`);
|
console.log(`We have chat template ${chat_template.split('\n')[0]}...`);
|
||||||
const templates = await deriveTemplatesFromChatTemplate(chat_template, chat_template_hash);
|
const templates = await deriveTemplatesFromChatTemplate(chat_template, chat_template_hash);
|
||||||
if (templates) {
|
if (templates) {
|
||||||
const { context, instruct } = templates;
|
const { context, instruct } = templates;
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
// 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'].encode()).hexdigest())"
|
// 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'].encode()).hexdigest())"
|
||||||
// note that chat templates must be trimmed to match the llama.cpp metadata value
|
// note that chat templates must be trimmed to match the llama.cpp metadata value
|
||||||
const derivations = {
|
const hash_derivations = {
|
||||||
// Meta
|
// Meta
|
||||||
'e10ca381b1ccc5cf9db52e371f3b6651576caee0a630b452e2816b2d404d4b65':
|
'e10ca381b1ccc5cf9db52e371f3b6651576caee0a630b452e2816b2d404d4b65':
|
||||||
// Meta-Llama-3.1-8B-Instruct
|
// Meta-Llama-3.1-8B-Instruct
|
||||||
@@ -51,17 +51,27 @@ const derivations = {
|
|||||||
,
|
,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const substr_derivations = {
|
||||||
|
'<|im_start|>': 'ChatML', // qwen2.5, ...
|
||||||
|
}
|
||||||
|
|
||||||
|
const parse_derivation = derivation => (typeof derivation === 'string') ? {
|
||||||
|
'context': derivation,
|
||||||
|
'instruct': derivation,
|
||||||
|
} : derivation;
|
||||||
|
|
||||||
export async function deriveTemplatesFromChatTemplate(chat_template, hash) {
|
export async function deriveTemplatesFromChatTemplate(chat_template, hash) {
|
||||||
if (hash in derivations) {
|
if (hash in hash_derivations) {
|
||||||
const derivation = derivations[hash];
|
return parse_derivation(hash_derivations[hash]);
|
||||||
if (typeof derivation === 'string') {
|
|
||||||
return {
|
|
||||||
'context': derivation,
|
|
||||||
'instruct': derivation,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return derivation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// heuristics
|
||||||
|
for (const [substr, derivation] of Object.entries(substr_derivations) ) {
|
||||||
|
if (chat_template.includes(substr)) {
|
||||||
|
return parse_derivation(derivation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
console.log(`Unknown chat template hash: ${hash} for [${chat_template}]`);
|
console.log(`Unknown chat template hash: ${hash} for [${chat_template}]`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user