templates : fix double-escaping in gpt-oss tool call arguments and responses
When tool_call.arguments is already a JSON string (as sent by the OpenAI
API), applying |tojson wraps it in quotes and escapes internal quotes,
producing double-escaped output like "{\"key\":\"val\"}" instead of
{"key":"val"}.
Add an `is string` guard (same pattern used by Hermes, Qwen3 templates)
so arguments are output as-is when already a string, and only serialized
via tojson when they are a dict/object.
Similarly, remove |tojson from tool response message.content which is
always a string from the API.
Fixes #19520
This commit is contained in:
parent
06705fdcb3
commit
f36fcfb825
|
|
@ -296,7 +296,11 @@
|
|||
{{- "<|start|>assistant to=" }}
|
||||
{{- "functions." + tool_call.name + "<|channel|>commentary " }}
|
||||
{{- (tool_call.content_type if tool_call.content_type is defined else "json") + "<|message|>" }}
|
||||
{{- tool_call.arguments|tojson }}
|
||||
{%- if tool_call.arguments is string -%}
|
||||
{{- tool_call.arguments }}
|
||||
{%- else -%}
|
||||
{{- tool_call.arguments | tojson }}
|
||||
{%- endif -%}
|
||||
{{- "<|call|>" }}
|
||||
{%- set last_tool_call.name = tool_call.name %}
|
||||
{%- elif loop.last and not add_generation_prompt %}
|
||||
|
|
@ -319,7 +323,7 @@
|
|||
{{- raise_exception("Message has tool role, but there was no previous assistant message with a tool call!") }}
|
||||
{%- endif %}
|
||||
{{- "<|start|>functions." + last_tool_call.name }}
|
||||
{{- " to=assistant<|channel|>commentary<|message|>" + message.content|tojson + "<|end|>" }}
|
||||
{{- " to=assistant<|channel|>commentary<|message|>" + message.content + "<|end|>" }}
|
||||
{%- elif message.role == 'user' -%}
|
||||
{{- "<|start|>user<|message|>" + message.content + "<|end|>" }}
|
||||
{%- endif -%}
|
||||
|
|
|
|||
Loading…
Reference in New Issue