palmfuture ThrBil commited on
Commit
00a6698
·
1 Parent(s): d1fef18

chat_template: replace no-user-query raise_exception with tolerant fallback (#3)

Browse files

- chat_template: replace no-user-query raise_exception with tolerant fallback (c75415f4b02af35a74b6205f35eef5d8ef495901)


Co-authored-by: William Threewits <ThrBil@users.noreply.huggingface.co>

Files changed (1) hide show
  1. chat_template.jinja +6 -1
chat_template.jinja CHANGED
@@ -76,7 +76,12 @@
76
  {%- endif %}
77
  {%- endfor %}
78
  {%- if ns.multi_step_tool %}
79
- {{- raise_exception('No user query found in messages.') }}
 
 
 
 
 
80
  {%- endif %}
81
  {%- for message in messages %}
82
  {%- set content = render_content(message.content, true)|trim %}
 
76
  {%- endif %}
77
  {%- endfor %}
78
  {%- if ns.multi_step_tool %}
79
+ {#- Tolerate conversations with no plain user turn (e.g. [system, assistant, tool, ...],
80
+ common in agent frameworks after history compression). The hard raise breaks every
81
+ runtime that renders the template at tool-parser-generation time (vLLM >=0.24,
82
+ llama.cpp, LM Studio, Ollama): the request 400s before a single token is generated.
83
+ -1 == "no user query" == preserve reasoning content on all assistant turns. #}
84
+ {%- set ns.last_query_index = -1 %}
85
  {%- endif %}
86
  {%- for message in messages %}
87
  {%- set content = render_content(message.content, true)|trim %}