Feat: Add toolcall description
#32
by
eric8810
- opened
- assets/chat_template.jinja +14 -4
assets/chat_template.jinja
CHANGED
|
@@ -15,6 +15,16 @@
|
|
| 15 |
{%- endif %}
|
| 16 |
{%- endif %}
|
| 17 |
{%- endfor %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
{{ bos_token }}{{ ns.system_prompt }}
|
| 19 |
{%- for message in messages %}
|
| 20 |
{%- if message['role'] == 'user' %}
|
|
@@ -33,13 +43,13 @@
|
|
| 33 |
{%- for tool in message['tool_calls'] %}
|
| 34 |
{%- if not ns.is_first %}
|
| 35 |
{%- if message['content'] is none %}
|
| 36 |
-
{{'<|tool▁calls▁begin|><|tool▁call▁begin|>'+ tool['function']['name'] + '<|tool▁sep|>' + tool['function']['arguments'] + '<|tool▁call▁end|>'}}
|
| 37 |
{%- else %}
|
| 38 |
-
{{message['content'] + '<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['function']['name'] + '<|tool▁sep|>' + tool['function']['arguments'] + '<|tool▁call▁end|>'}}
|
| 39 |
{%- endif %}
|
| 40 |
{%- set ns.is_first = true -%}
|
| 41 |
{%- else %}
|
| 42 |
-
{{'<|tool▁call▁begin|>'+ tool['function']['name'] + '<|tool▁sep|>' + tool['function']['arguments'] + '<|tool▁call▁end|>'}}
|
| 43 |
{%- endif %}
|
| 44 |
{%- endfor %}
|
| 45 |
{{'<|tool▁calls▁end|><|end▁of▁sentence|>'}}
|
|
@@ -78,4 +88,4 @@
|
|
| 78 |
{%- else %}
|
| 79 |
{{'<think>'}}
|
| 80 |
{%- endif %}
|
| 81 |
-
{% endif %}
|
|
|
|
| 15 |
{%- endif %}
|
| 16 |
{%- endif %}
|
| 17 |
{%- endfor %}
|
| 18 |
+
|
| 19 |
+
{% if tools is defined and tools is not none %}
|
| 20 |
+
{% set tool_ns = namespace(text='## Tools\nYou have access to the following tools:\n') %}
|
| 21 |
+
{% for tool in tools %}
|
| 22 |
+
{% set tool_ns.text = tool_ns.text + '\n### ' + tool.function.name + '\nDescription: ' + tool.function.description + '\n\nParameters: ' + (tool.function.parameters | tojson) + '\n' %}
|
| 23 |
+
{% endfor %}
|
| 24 |
+
{% set tool_ns.text = tool_ns.text + "\nIMPORTANT: ALWAYS adhere to this exact format for tool use:\n<|tool▁calls▁begin|><|tool▁call▁begin|>tool_call_name<|tool▁sep|>tool_call_arguments<|tool▁call▁end|>{{additional_tool_calls}}<|tool▁calls▁end|>\n\nWhere:\n\n- `tool_call_name` must be an exact match to one of the available tools\n- `tool_call_arguments` must be valid JSON that strictly follows the tool's Parameters Schema\n- For multiple tool calls, chain them directly without separators or spaces\n" %}
|
| 25 |
+
{% set ns.system_prompt = ns.system_prompt + '\n\n' + tool_ns.text %}
|
| 26 |
+
{% endif %}
|
| 27 |
+
|
| 28 |
{{ bos_token }}{{ ns.system_prompt }}
|
| 29 |
{%- for message in messages %}
|
| 30 |
{%- if message['role'] == 'user' %}
|
|
|
|
| 43 |
{%- for tool in message['tool_calls'] %}
|
| 44 |
{%- if not ns.is_first %}
|
| 45 |
{%- if message['content'] is none %}
|
| 46 |
+
{{'<|tool▁calls▁begin|><|tool▁call▁begin|>'+ tool['function']['name'] + '<|tool▁sep|>' + tool['function']['arguments']|tojson + '<|tool▁call▁end|>'}}
|
| 47 |
{%- else %}
|
| 48 |
+
{{message['content'] + '<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['function']['name'] + '<|tool▁sep|>' + tool['function']['arguments']|tojson + '<|tool▁call▁end|>'}}
|
| 49 |
{%- endif %}
|
| 50 |
{%- set ns.is_first = true -%}
|
| 51 |
{%- else %}
|
| 52 |
+
{{'<|tool▁call▁begin|>'+ tool['function']['name'] + '<|tool▁sep|>' + tool['function']['arguments']|tojson + '<|tool▁call▁end|>'}}
|
| 53 |
{%- endif %}
|
| 54 |
{%- endfor %}
|
| 55 |
{{'<|tool▁calls▁end|><|end▁of▁sentence|>'}}
|
|
|
|
| 88 |
{%- else %}
|
| 89 |
{{'<think>'}}
|
| 90 |
{%- endif %}
|
| 91 |
+
{% endif %}
|