DavidAU commited on
Commit
a9667ec
·
verified ·
1 Parent(s): a54efdf

Upload chat_template.jinja

Browse files
Files changed (1) hide show
  1. chat_template.jinja +95 -0
chat_template.jinja ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if not thinking is defined %}{% set thinking = false %}{% endif %}
2
+ {%- if tools %}
3
+ {{- '<|im_start|>system\n' }}
4
+ {%- if messages[0].role == 'system' %}
5
+ {{- messages[0].content + '\n\n' }}
6
+ {%- endif %}
7
+ {{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
8
+ {%- for tool in tools %}
9
+ {{- "\n" }}
10
+ {{- tool | tojson }}
11
+ {%- endfor %}
12
+ {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
13
+ {%- else %}
14
+ {%- if messages[0].role == 'system' %}
15
+ {{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
16
+ {%- endif %}
17
+ {%- endif %}
18
+ {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
19
+ {%- for message in messages[::-1] %}
20
+ {%- set index = (messages|length - 1) - loop.index0 %}
21
+ {%- if ns.multi_step_tool and message.role == "user" and message.content is string and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}
22
+ {%- set ns.multi_step_tool = false %}
23
+ {%- set ns.last_query_index = index %}
24
+ {%- endif %}
25
+ {%- endfor %}
26
+ {%- for message in messages %}
27
+ {%- if message.content is string %}
28
+ {%- set content = message.content %}
29
+ {%- else %}
30
+ {%- set content = '' %}
31
+ {%- endif %}
32
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
33
+ {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
34
+ {%- elif message.role == "assistant" %}
35
+ {%- set reasoning_content = '' %}
36
+ {%- if message.reasoning_content is string %}
37
+ {%- set reasoning_content = message.reasoning_content %}
38
+ {%- else %}
39
+ {%- if '</think>' in content %}
40
+ {%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
41
+ {%- set content = content.split('</think>')[-1].lstrip('\n') %}
42
+ {%- endif %}
43
+ {%- endif %}
44
+ {%- if loop.index0 > ns.last_query_index %}
45
+ {%- if loop.last or (not loop.last and reasoning_content) %}
46
+ {%- if thinking %}
47
+ {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
48
+ {%- else %}
49
+ {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
50
+ {%- endif %}
51
+ {%- else %}
52
+ {{- '<|im_start|>' + message.role + '\n' + content }}
53
+ {%- endif %}
54
+ {%- else %}
55
+ {{- '<|im_start|>' + message.role + '\n' + content }}
56
+ {%- endif %}
57
+ {%- if message.tool_calls %}
58
+ {%- for tool_call in message.tool_calls %}
59
+ {%- if (loop.first and content) or (not loop.first) %}
60
+ {{- '\n' }}
61
+ {%- endif %}
62
+ {%- if tool_call.function %}
63
+ {%- set tool_call = tool_call.function %}
64
+ {%- endif %}
65
+ {{- '<tool_call>\n{"name": "' }}
66
+ {{- tool_call.name }}
67
+ {{- '", "arguments": ' }}
68
+ {%- if tool_call.arguments is string %}
69
+ {{- tool_call.arguments }}
70
+ {%- else %}
71
+ {{- tool_call.arguments | tojson }}
72
+ {%- endif %}
73
+ {{- '}\n</tool_call>' }}
74
+ {%- endfor %}
75
+ {%- endif %}
76
+ {{- '<|im_end|>\n' }}
77
+ {%- elif message.role == "tool" %}
78
+ {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
79
+ {{- '<|im_start|>user' }}
80
+ {%- endif %}
81
+ {{- '\n<tool_response>\n' }}
82
+ {{- content }}
83
+ {{- '\n</tool_response>' }}
84
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
85
+ {{- '<|im_end|>\n' }}
86
+ {%- endif %}
87
+ {%- endif %}
88
+ {%- endfor %}
89
+ {%- if add_generation_prompt %}
90
+ {%- if thinking %}
91
+ {{- '<|im_start|>assistant\n<think>\n' }}
92
+ {%- else %}
93
+ {{- '<|im_start|>assistant\n' }}
94
+ {%- endif %}
95
+ {%- endif %}