-
Notifications
You must be signed in to change notification settings - Fork 15.6k
Add workaround for templates requiring non-null content #19056
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2393b17
ede9586
7a54851
8570683
20db3d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -160,7 +160,7 @@ caps caps_get(jinja::program & prog) { | |
| {"content", "Assistant message"}, | ||
| {"tool_calls", json::array({ | ||
| { | ||
| {"id", "call1"}, | ||
| {"id", "call00001"}, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably useful to leave a comment header explaining why the ID must be at a certain length (IIRC there was one or two templates enforces this?) just in case we may come up with a better way in the future, we can come back and test the problematic template
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, I'll add. |
||
| {"type", "function"}, | ||
| {"function", { | ||
| {"name", "tool1"}, | ||
|
|
@@ -170,10 +170,10 @@ caps caps_get(jinja::program & prog) { | |
| }} | ||
| }, | ||
| { | ||
| {"id", "call2"}, | ||
| {"id", "call00002"}, | ||
| {"type", "function"}, | ||
| {"function", { | ||
| {"name", "tool2"}, | ||
| {"name", "tool1"}, | ||
| {"arguments", { | ||
| {"arg", "value"} | ||
| }} | ||
|
|
@@ -194,7 +194,7 @@ caps caps_get(jinja::program & prog) { | |
| {"name", "tool"}, | ||
| {"type", "function"}, | ||
| {"function", { | ||
| {"name", "tool"}, | ||
| {"name", "tool1"}, | ||
| {"description", "Tool description"}, | ||
| {"parameters", { | ||
| {"type", "object"}, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -949,6 +949,19 @@ static void test_tests(testing & t) { | |||||||||||||||||||||||||||||
| {{"x", {{"a", 1}}}}, | ||||||||||||||||||||||||||||||
| "yes" | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| test_template(t, "something in undefined", | ||||||||||||||||||||||||||||||
| "{% if x in y %}yes{% else %}no{% endif %}", | ||||||||||||||||||||||||||||||
| {{"x", 1}}, | ||||||||||||||||||||||||||||||
| "no" | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| test_template(t, "null is undefined", | ||||||||||||||||||||||||||||||
| "{% if null is not defined %}yes{% else %}no{% endif %}", | ||||||||||||||||||||||||||||||
| json::object(), | ||||||||||||||||||||||||||||||
| "yes" | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
Comment on lines
+958
to
965
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
What are you trying to test here, we already have this test ( llama.cpp/tests/test-jinja.cpp Lines 189 to 193 in 20db3d4
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I wanted to do the explicit "null constant is alias for undefined" check. |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| static void test_string_methods(testing & t) { | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure if this is expected by all templates. in theory, there can be regression in these cases:
if content is not none: (do something) else (do other things)<message><tool>...</tool><content></content></message>--> in such case, content maybe expected to be nonebut that's just in theory, for now I can't think of a way to verify it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the same, but @aldehir talked me out of it 😀 can always add the cap code if we change our mind.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to recall, but I believe this is where simply checking "non-null" is insufficient:
llama.cpp/models/templates/Qwen-Qwen3-0.6B.jinja
Lines 40 to 42 in bb02f74
This branch is only explored with a tool call + reasoning content. The Qwen3 template was not triggering the
requires non-nullcheck in Minja, so we were passingnullcontent and it was throwing an exception. I think most templates are defensive against empty content, more than null content. A default of an empty string seems more reasonable to me. We are already passing in an empty string as of #18485. The capability checks do not align with this.