m-i commited on
Commit
e5a840e
·
verified ·
1 Parent(s): 01193ab

Upload chat_template.jinja with huggingface_hub

Browse files
Files changed (1) hide show
  1. chat_template.jinja +91 -0
chat_template.jinja ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if tools %}
2
+ {{- '<|im_start|>system\n' }}
3
+ {%- if messages[0].role == 'system' %}
4
+ {{- messages[0].content + '\n\n' }}
5
+ {%- endif %}
6
+ {{- "# 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>" }}
7
+ {%- for tool in tools %}
8
+ {{- "\n" }}
9
+ {{- tool | tojson }}
10
+ {%- endfor %}
11
+ {{- "\n</tools>\n\nFor each function call, use this XML format:\n\n<function=function_name>\n <parameter=param1>value1</parameter>\n <parameter=param2>value2</parameter>\n</function>\n" }}
12
+ {%- else %}
13
+ {%- if messages[0].role == 'system' %}
14
+ {{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
15
+ {%- endif %}
16
+ {%- endif %}
17
+
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
+ {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
47
+ {%- else %}
48
+ {{- '<|im_start|>' + message.role + '\n' + content }}
49
+ {%- endif %}
50
+ {%- else %}
51
+ {{- '<|im_start|>' + message.role + '\n' + content }}
52
+ {%- endif %}
53
+ {%- if message.tool_calls %}
54
+ {%- for tool_call in message.tool_calls %}
55
+ {%- if (loop.first and content) or (not loop.first) %}
56
+ {{- '\n' }}
57
+ {%- endif %}
58
+ {%- if tool_call.function %}
59
+ {%- set tool_call = tool_call.function %}
60
+ {%- endif %}
61
+ {{- '<function=' + tool_call.name + '>\n' }}
62
+ {%- if tool_call.arguments is string %}
63
+ {%- set args = tool_call.arguments | fromjson %}
64
+ {%- else %}
65
+ {%- set args = tool_call.arguments %}
66
+ {%- endif %}
67
+ {%- for param_name, param_value in args.items() %}
68
+ {{- ' <parameter=' + param_name + '>' + (param_value | string) + '</parameter>\n' }}
69
+ {%- endfor %}
70
+ {{- '</function>' }}
71
+ {%- endfor %}
72
+ {%- endif %}
73
+ {{- '<|im_end|>\n' }}
74
+ {%- elif message.role == "tool" %}
75
+ {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
76
+ {{- '<|im_start|>user' }}
77
+ {%- endif %}
78
+ {{- '\n<tool_response>\n' }}
79
+ {{- content }}
80
+ {{- '\n</tool_response>' }}
81
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
82
+ {{- '<|im_end|>\n' }}
83
+ {%- endif %}
84
+ {%- endif %}
85
+ {%- endfor %}
86
+ {%- if add_generation_prompt %}
87
+ {{- '<|im_start|>assistant\n' }}
88
+ {%- if enable_thinking is defined and enable_thinking is false %}
89
+ {{- '<think>\n\n</think>\n\n' }}
90
+ {%- endif %}
91
+ {%- endif %}