mstyslavity commited on
Commit
d8690ea
·
verified ·
1 Parent(s): 58258e0

Upload chat_template.jinja with huggingface_hub

Browse files
Files changed (1) hide show
  1. chat_template.jinja +101 -0
chat_template.jinja ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ {%- set thinking_prefix = thinking_prefix or 'Begin by thinking about the reasoning process in the mind within <think> </think> tags and then proceed to give your response.\n' -%}
3
+
4
+ {%- if bos_token is defined and bos_token is not none %}{{- bos_token -}}{%- endif %}
5
+ {%- if tools %}
6
+ {{- '<|im_start|>system\n' }}
7
+ {%- if messages|length > 0 and messages[0].role == 'system' %}
8
+ {{- messages[0].content + '\n\n' }}
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|length > 0 and messages[0].role == 'system' %}
18
+ {{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
19
+ {%- endif %}
20
+ {%- endif %}
21
+ {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
22
+ {%- for message in messages[::-1] %}
23
+ {%- set index = (messages|length - 1) - loop.index0 %}
24
+ {%- if ns.multi_step_tool and message.role == "user" and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}
25
+ {%- set ns.multi_step_tool = false %}
26
+ {%- set ns.last_query_index = index %}
27
+ {%- endif %}
28
+ {%- endfor %}
29
+ {%- for message in messages %}
30
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
31
+ {%- set prefix = '' %}
32
+ {%- if message.role == 'user' and '<think>' not in message.content %}
33
+ {%- if loop.last %}
34
+ {%- set prefix = thinking_prefix %}
35
+ {%- endif %}
36
+ {%- if not loop.last %}
37
+ {%- if loop.nextitem.role == 'assistant' and loop.nextitem.content.startswith('<think>') or loop.nextitem.reasoning_content is defined and loop.nextitem.reasoning_content is not none %}
38
+ {%- set prefix = thinking_prefix %}
39
+ {%- endif %}
40
+ {%- endif %}
41
+ {%- endif %}
42
+ {%- if message.role == 'user' and not loop.last and loop.nextitem.role == 'assistant' and loop.nextitem.content.startswith('<think>') and '<think>' not in message.content %}
43
+ {%- set prefix = thinking_prefix %}
44
+ {%- endif %}
45
+ {{- '<|im_start|>' + message.role + '\n' + prefix + message.content + '<|im_end|>' + '\n' }}
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 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
+ {{- '<think>\n' }}
101
+ {%- endif -%}