Updating chat template of LFM2 to render tools in correct format | enabling minja for that model - #4411
Open
przepeck wants to merge 4 commits into
Open
Updating chat template of LFM2 to render tools in correct format | enabling minja for that model#4411przepeck wants to merge 4 commits into
przepeck wants to merge 4 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the LFM2 chat template used by OVMS LLM tests/examples so that prior assistant tool calls are serialized in the LFM2 tool-call token format (and can be processed by Minja), aligning prompt rendering with LFM2 tool-call expectations.
Changes:
- Added Jinja macros to render
tool_callsas<|tool_call_start|>[func(arg=...)]<|tool_call_end|>in the LFM2 chat template. - Updated end-to-end Minja/Jinja tests to expect LFM2 tool-call rendering and tool-call capability detection.
- Added an
extras/example LFM2 chat template mirroring the test template.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/test/llm/chat_templates/chat_template_lfm2.jinja | Adds tool-call rendering macros and emits tool calls in LFM2 format during prompt construction. |
| src/test/llm/chat_template_end_to_end_minja_test.cpp | Updates Minja end-to-end expectations for LFM2 tool-call rendering/capabilities. |
| src/test/llm/chat_template_end_to_end_jinja_test.cpp | Updates Jinja end-to-end expectations for LFM2 tool-call rendering/capabilities. |
| extras/chat_template_examples/chat_template_lfm2.jinja | Introduces an example LFM2 template matching the updated tool-call rendering behavior. |
Comments suppressed due to low confidence (2)
src/test/llm/chat_templates/chat_template_lfm2.jinja:86
- The template renders tool-call markers whenever
tool_callsis defined, even if it is an empty list. That produces<|tool_call_start|>[]<|tool_call_end|>in the prompt, which is likely unintended and can confuse downstream parsing.
{%- if message["tool_calls"] is defined -%}
{{- render_tool_calls(message["tool_calls"]) -}}
{%- endif -%}
extras/chat_template_examples/chat_template_lfm2.jinja:86
- The template renders tool-call markers whenever
tool_callsis defined, even if it is an empty list. That produces<|tool_call_start|>[]<|tool_call_end|>in the prompt, which is likely unintended and can confuse downstream parsing.
{%- if message["tool_calls"] is defined -%}
{{- render_tool_calls(message["tool_calls"]) -}}
{%- endif -%}
Comment on lines
+4
to
+10
| {%- if arg_value is string -%} | ||
| {{- "'" + arg_value + "'" -}} | ||
| {%- elif arg_value is mapping -%} | ||
| {{- arg_value | tojson -}} | ||
| {%- else -%} | ||
| {{- arg_value | string -}} | ||
| {%- endif -%} |
Comment on lines
+4
to
+10
| {%- if arg_value is string -%} | ||
| {{- "'" + arg_value + "'" -}} | ||
| {%- elif arg_value is mapping -%} | ||
| {{- arg_value | tojson -}} | ||
| {%- else -%} | ||
| {{- arg_value | string -}} | ||
| {%- endif -%} |
dtrawins
reviewed
Jul 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🛠 Summary
CVS-186942
Changing the chat template of LFM2 to render executed tools. This chat templates also works with Minja.
BFCL results:
Multi_turn_base:
Multiturn score with old chat template: 0.266
Multiturn score with new chat template: 0.32
Simple_python:
Llama.cpp: 37.75
OVMS with new chat template: 39.25
🧪 Checklist
``