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