Optimize templates
This commit is contained in:
parent
ce67d07269
commit
adc55d3001
|
|
@ -236,13 +236,17 @@ export namespace Huggingface {
|
||||||
|
|
||||||
if (config?.chat_template?.trim()) {
|
if (config?.chat_template?.trim()) {
|
||||||
template = config.chat_template.trim()
|
template = config.chat_template.trim()
|
||||||
|
.replace(/raise_exception\(('[^')]+'|"[^")]+")\)/g, `''`)
|
||||||
.replaceAll('eos_token', `'${config.eos_token ?? ''}'`)
|
.replaceAll('eos_token', `'${config.eos_token ?? ''}'`)
|
||||||
.replaceAll('bos_token', `''`);
|
.replaceAll('bos_token', `''`)
|
||||||
|
.replace(/\{\{ ?(''|"") ?\}\}/g, '')
|
||||||
if (config.bos_token) {
|
.replace(/\n'/g, `\\n'`)
|
||||||
template = template
|
.replace(/\n"/g, `\\n"`)
|
||||||
.replace(/\{\{ ?(''|"") ?\}\}/g, '');
|
.replace(/'\s*\+\s*'/g, '')
|
||||||
}
|
.replace(/"\s*\+\s*"/g, '')
|
||||||
|
.replace(/\{%\s*else\s*%\}\{%\s*endif\s*%\}/gi, '{% endif %}')
|
||||||
|
.replace(/\{%\s*elif[^}]+%\}\{%\s*endif\s*%\}/gi, '{% endif %}')
|
||||||
|
.replace(/\{%\s*if[^}]+%\}\{%\s*endif\s*%\}/gi, '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -308,7 +312,6 @@ export namespace Huggingface {
|
||||||
try {
|
try {
|
||||||
let template = compiledTemplates.get(templateString);
|
let template = compiledTemplates.get(templateString);
|
||||||
if (!template) {
|
if (!template) {
|
||||||
templateString = templateString.replace(/raise_exception\(('[^')]+'|"[^")]+")\)/g, `''`)
|
|
||||||
template = new Template(templateString);
|
template = new Template(templateString);
|
||||||
compiledTemplates.set(templateString, template);
|
compiledTemplates.set(templateString, template);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue