Files
usatama-8b-grpo-phase2/chat_template.jinja
ModelHub XC 2f63b8cef0 初始化项目,由ModelHub XC社区提供模型
Model: SousiOmine/usatama-8b-grpo-phase2
Source: Original Platform
2026-06-27 15:42:19 +08:00

206 lines
7.9 KiB
Django/Jinja

{%- set allowed_effort = ["none", "low", "medium", "high"] -%}
{%- set reasoning_effort = reasoning_effort if reasoning_effort is defined and reasoning_effort in allowed_effort else "medium" -%}
{%- set default_system_prompt = "You are LLM-jp-4, a large language model trained by LLM-jp." -%}
{%- set message_end = "<|im_end|>\n" -%}
{%- set assistant_end = eos_token if eos_token is defined else "<|return|>" -%}
{%- macro tool_to_json(tool) -%}
{%- set ns_tool = namespace(first=true) -%}
{{ "{" -}}
{%- for k, v in tool.items() -%}
{%- if k != "defer_loading" and k != "strict" -%}
{%- if not ns_tool.first -%}{{- ", " -}}{%- endif -%}
{%- set ns_tool.first = false -%}
"{{ k }}": {{ v | tojson(ensure_ascii=False) }}
{%- endif -%}
{%- endfor -%}
{{- "}" -}}
{%- endmacro -%}
{%- macro render_content(content) -%}
{%- if content is string -%}
{{- content -}}
{%- elif content is mapping -%}
{%- if content.text is defined -%}
{{- content.text -}}
{%- else -%}
{{- content | tojson(ensure_ascii=False) -}}
{%- endif -%}
{%- elif content is iterable -%}
{%- for item in content -%}
{%- if item is string -%}
{{- item -}}
{%- elif item is mapping -%}
{%- if item.type is defined and item.type == "text" and item.text is defined -%}
{{- item.text -}}
{%- elif item.text is defined -%}
{{- item.text -}}
{%- else -%}
{{- item | tojson(ensure_ascii=False) -}}
{%- endif -%}
{%- else -%}
{{- item | string -}}
{%- endif -%}
{%- endfor -%}
{%- elif content is none or content is undefined -%}
{%- else -%}
{{- content | string -}}
{%- endif -%}
{%- endmacro -%}
{%- if tools -%}
<|im_start|>system
# ツール
タスクを解決するために、1つまたは複数のツールを呼び出すことができます。
ツールのシグネチャは、<tools></tools> XMLタグ内に記載されています。
<tools>
{% for tool in tools %}
{%- if "function" in tool -%}
{%- set tool = tool["function"] -%}
{%- endif -%}
{%- if tool.defer_loading is not defined or not tool.defer_loading -%}
{{ tool_to_json(tool) }}
{{- "\n" }}
{%- endif -%}
{% endfor %}
</tools>
ツールを呼び出す場合は、以下の形式で回答し、後ろに言葉を付け加えないでください。
<tool_call>
<function=example_function_name>
<parameter=example_parameter_1>
value_1
</parameter>
<parameter=example_parameter_2>
This is the value for the second parameter
</parameter>
</function>
</tool_call>
{%- if messages and messages[0].role == "system" %}
{{- "\n\n" + (render_content(messages[0].content)|trim) }}
{%- else %}
{{- "\n\n" + default_system_prompt }}
{%- endif %}
{{- "\n\nReasoning effort: " + reasoning_effort }}
{{- message_end }}
{%- elif messages and messages[0].role == "system" -%}
{{- "<|im_start|>system\n" + (render_content(messages[0].content)|trim) + "\n\nReasoning effort: " + reasoning_effort + message_end }}
{%- else -%}
{{- "<|im_start|>system\n" + default_system_prompt + "\n\nReasoning effort: " + reasoning_effort + message_end }}
{%- endif -%}
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) -%}
{%- for message in messages[::-1] -%}
{%- set index = (messages|length - 1) - loop.index0 -%}
{%- if ns.multi_step_tool and message.role == "user" -%}
{%- set content = render_content(message.content)|trim -%}
{%- if not(content.startswith("<tool_response>") and content.endswith("</tool_response>")) -%}
{%- set ns.multi_step_tool = false -%}
{%- set ns.last_query_index = index -%}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{%- if ns.multi_step_tool %}
{{- raise_exception("No user query found in messages.") }}
{%- endif -%}
{%- for message in messages -%}
{%- set content = render_content(message.content)|trim -%}
{%- if message.role == "system" %}
{%- if not loop.first %}
{{- raise_exception("System message must be at the beginning.") }}
{%- endif %}
{%- elif message.role == "user" -%}
{{- "<|im_start|>user\n" + content + message_end }}
{%- elif message.role == "assistant" %}
{%- set reasoning_content = "" -%}
{%- if message.reasoning_content is string -%}
{%- set reasoning_content = message.reasoning_content -%}
{%- else -%}
{%- if "</think>" in content -%}
{%- set reasoning_content = content.split("</think>")[0].rstrip("\n").split("<think>")[-1].lstrip("\n") -%}
{%- set content = content.split("</think>")[-1].lstrip("\n") -%}
{%- endif -%}
{%- endif -%}
{%- set reasoning_content = reasoning_content|trim -%}
{%- if loop.index0 > ns.last_query_index %}
{{- "<|im_start|>assistant\n<think>\n" + reasoning_content + "\n</think>\n\n" + content }}
{%- else %}
{{- "<|im_start|>assistant\n" + content }}
{%- endif %}
{%- if message.tool_calls is defined and message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}
{%- for tool_call in message.tool_calls %}
{%- if tool_call.function is defined %}
{%- set tool_call = tool_call.function %}
{%- endif %}
{%- if loop.first %}
{%- if content|trim %}
{{- "\n\n<tool_call>\n<function=" + tool_call.name + ">\n" }}
{%- else %}
{{- "<tool_call>\n<function=" + tool_call.name + ">\n" }}
{%- endif %}
{%- else %}
{{- "\n<tool_call>\n<function=" + tool_call.name + ">\n" }}
{%- endif %}
{%- if tool_call.arguments is defined and tool_call.arguments is not none %}
{%- if tool_call.arguments is mapping %}
{%- for args_name, args_value in tool_call.arguments|items %}
{{- "<parameter=" + args_name + ">\n" }}
{%- set args_value = args_value | tojson(ensure_ascii=False) if args_value is mapping or (args_value is iterable and args_value is not string and args_value is not mapping) else args_value | string %}
{{- args_value }}
{{- "\n</parameter>\n" }}
{%- endfor %}
{%- elif tool_call.arguments is string %}
{{- raise_exception("tool_call.arguments must be a mapping.") }}
{%- else %}
{{- raise_exception("tool_call.arguments must be a mapping.") }}
{%- endif %}
{%- endif %}
{{- "</function>\n</tool_call>\n" }}
{%- endfor %}
{%- endif %}
{{- assistant_end }}
{%- elif message.role == "tool" %}
{%- if loop.previtem and loop.previtem.role != "tool" %}
{{- "<|im_start|>user" }}
{%- endif %}
{{- "\n<tool_response" }}
{%- if message.tool_call_id is defined and message.tool_call_id %}
{{- " id=\"" + (message.tool_call_id|string) + "\"" }}
{%- endif %}
{{- ">\n" }}
{{- content }}
{{- "\n</tool_response>" }}
{%- if loop.last or loop.nextitem.role != "tool" %}
{{- message_end }}
{%- endif %}
{%- else %}
{{- raise_exception("Unexpected message role.") }}
{%- endif %}
{%- endfor -%}
{%- if add_generation_prompt %}
{{- "<|im_start|>assistant\n" }}
{%- if reasoning_effort == "none" %}
{{- "<think>\n\n</think>\n\n" }}
{%- else %}
{{- "<think>\n" }}
{%- endif %}
{%- endif %}