introvoyz041 commited on
Commit
7932878
·
verified ·
1 Parent(s): 3fa8c0d

Upload chat_template.jinja with huggingface_hub

Browse files
Files changed (1) hide show
  1. chat_template.jinja +88 -0
chat_template.jinja ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {#- Unsloth template fixes #}
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 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.role == "user") or (message.role == "system" and not loop.first) %}
28
+ {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
29
+ {%- elif message.role == "assistant" %}
30
+ {%- set content = message.content if message.content is defined else '' %}
31
+ {%- set content = content if content is not none else '' %}
32
+ {%- set reasoning_content = '' %}
33
+ {%- if message.reasoning_content is defined and message.reasoning_content is not none %}
34
+ {%- set reasoning_content = message.reasoning_content %}
35
+ {%- else %}
36
+ {%- if '</think>' in message.content %}
37
+ {%- set content = (message.content.split('</think>')|last).lstrip('\n') %}
38
+ {%- set reasoning_content = ((message.content.split('</think>')|first).rstrip('\n').split('<think>')|last).lstrip('\n') %}
39
+ {%- endif %}
40
+ {%- endif %}
41
+ {%- if loop.index0 > ns.last_query_index %}
42
+ {%- if loop.last or (not loop.last and reasoning_content) %}
43
+ {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
44
+ {%- else %}
45
+ {{- '<|im_start|>' + message.role + '\n' + content }}
46
+ {%- endif %}
47
+ {%- else %}
48
+ {{- '<|im_start|>' + message.role + '\n' + content }}
49
+ {%- endif %}
50
+ {%- if message.tool_calls %}
51
+ {%- for tool_call in message.tool_calls %}
52
+ {%- if (loop.first and content) or (not loop.first) %}
53
+ {{- '\n' }}
54
+ {%- endif %}
55
+ {%- if tool_call.function %}
56
+ {%- set tool_call = tool_call.function %}
57
+ {%- endif %}
58
+ {{- '<tool_call>\n{"name": "' }}
59
+ {{- tool_call.name }}
60
+ {{- '", "arguments": ' }}
61
+ {%- if tool_call.arguments is string %}
62
+ {{- tool_call.arguments }}
63
+ {%- else %}
64
+ {{- tool_call.arguments | tojson }}
65
+ {%- endif %}
66
+ {{- '}\n</tool_call>' }}
67
+ {%- endfor %}
68
+ {%- endif %}
69
+ {{- '<|im_end|>\n' }}
70
+ {%- elif message.role == "tool" %}
71
+ {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
72
+ {{- '<|im_start|>user' }}
73
+ {%- endif %}
74
+ {{- '\n<tool_response>\n' }}
75
+ {{- message.content }}
76
+ {{- '\n</tool_response>' }}
77
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
78
+ {{- '<|im_end|>\n' }}
79
+ {%- endif %}
80
+ {%- endif %}
81
+ {%- endfor %}
82
+ {%- if add_generation_prompt %}
83
+ {{- '<|im_start|>assistant\n' }}
84
+ {%- if enable_thinking is defined and enable_thinking is false %}
85
+ {{- '<think>\n\n</think>\n\n' }}
86
+ {%- endif %}
87
+ {%- endif %}
88
+ {#- Copyright 2025-present Unsloth. Apache 2.0 License. #}