introvoyz041 commited on
Commit
9af0862
·
verified ·
1 Parent(s): d5a6597

Upload chat_template.jinja with huggingface_hub

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