Open flatsiedatsie opened 1 month ago
Here's a console log with the variables split out first:
I've solved it by adding new TextDecoder
:
const pre_bos_token = window.llama_cpp_app.getBOS();
const pre_eos_token = window.llama_cpp_app.getEOS();
console.log("jinja: pre_bos_token: ", pre_bos_token);
console.log("jinja: pre_eos_token: ", pre_eos_token);
let bos_token = await window.llama_cpp_app.detokenize([window.llama_cpp_app.getBOS()])
let eos_token = await window.llama_cpp_app.detokenize([window.llama_cpp_app.getEOS()])
bos_token = new TextDecoder().decode(bos_token);
eos_token = new TextDecoder().decode(eos_token);
console.log("jinja: bos_token: ", bos_token);
console.log("jinja: eos_token: ", eos_token);
let rendered = template.render({
messages,
bos_token: bos_token,
eos_token: eos_token,
add_generation_prompt: true,
});
console.log("jinja: rendered: ", rendered);
(this issue can now be closed)
That was a great investigation!
bos_token: await window.llama_cpp_app.detokenize([window.llama_cpp_app.getBOS()]),
This is one of the reason why switching to typescript will save you some headaches.
The detokenize
function always returns Uint8Array
, not a string. If you try to input Uint8Array
into a function that needs string, typescript will tell you not to do that.
You do realize that code is from Wllama right? :-D
Hmm, right, the object inside template.render
is not typed.
In typescript, we can also force checking the type using satisfies
, for example this will cause error I mentioned above:
bos_token: await window.llama_cpp_app.detokenize([window.llama_cpp_app.getBOS()]) satisfies string,
After switching to the Jinja templating engine, I got the feeling that my default model (Danube 3 500m) wasn't giving the same answers.
So I did a test between the old and new version, and to my surprise there is a difference:
Transformers.js:
Jinja:
I then tried to use their latest Q4_K_M .gguf supplied by h2o.ai (for jinja) and also set their repo's latest config files (for Transformers.js). The result was the same.
I then compared the template that's embedded in the .gguf with the one in the config files. They were the same:
I then dove into the jinja template code, and realised I had noticed something odd earlier -
[object Map]
in the generated template - and had added some code to filter that out:Is the example code (from utils.js) I was using correct?