mrtoots commited on
Commit
fdd9206
·
verified ·
1 Parent(s): deda9c8

Upload chat_template.jinja with huggingface_hub

Browse files
Files changed (1) hide show
  1. chat_template.jinja +85 -0
chat_template.jinja ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {#- Unsloth template fixes #}
2
+ {%- set thinking_prompt = 'You are a deep thinking AI, you may use extremely long chains of thought to deeply consider the problem and deliberate with yourself via systematic reasoning processes to help come to a correct solution prior to answering. You should enclose your thoughts and internal monologue inside <think> </think> tags, and then provide your solution or response to the problem.' %}
3
+ {%- set standard_prompt = 'You are Hermes, created by Nous Research.' %}
4
+ {%- if enable_thinking is defined and enable_thinking is false %}{% set thinking = false %}
5
+ {%- elif enable_thinking is defined and enable_thinking is true %}{% set thinking = true %}
6
+ {%- elif not thinking is defined %}{% set thinking = false %}
7
+ {% endif %}
8
+ {%- if not keep_cots is defined %}{% set keep_cots = false %}{% endif %}
9
+ {%- if thinking %}{%- set system_prompt = thinking_prompt %}{%- else %}{%- set system_prompt = standard_prompt %}{%- endif %}
10
+ {%- if tools %}
11
+ {{- bos_token + '<|start_header_id|>system<|end_header_id|>\n' }}
12
+ {%- if messages[0]['role'] == 'system' %}
13
+ {{- messages[0]['content'] }}
14
+ {%- else %}
15
+ {{- system_prompt }}
16
+ {%- endif %}
17
+ {{- "\n\n# Tools\n\nYou are a function calling AI model. You 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>" }}
18
+ {%- for tool in tools %}
19
+ {{- "\n" }}
20
+ {{- tool | tojson }}
21
+ {%- endfor %}
22
+ {{- "\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><|eot_id|>" }}
23
+ {%- else %}
24
+ {%- if messages[0]['role'] == 'system' %}
25
+ {{- bos_token + '<|start_header_id|>system<|end_header_id|>\n\n' + messages[0]['content'] + '<|eot_id|>' }}
26
+ {%- else %}
27
+ {{- bos_token + '<|start_header_id|>system<|end_header_id|>\n\n' + system_prompt + '<|eot_id|>' }}
28
+ {%- endif %}
29
+ {%- endif %}
30
+ {%- for message in messages %}
31
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
32
+ {{- '<|start_header_id|>' + message.role + '<|end_header_id|>\n\n' + message.content + '<|eot_id|>' }}
33
+ {%- elif (message.role == "assistant" and not message.tool_calls) %}
34
+ {{- '<|start_header_id|>' + message.role + '<|end_header_id|>\n' }}
35
+ {%- if message.content %}
36
+ {%- set content = message['content'] -%}
37
+ {%- if thinking %}
38
+ {%- if not keep_cots %}
39
+ {%- set splitted = content.split('</think>') -%}
40
+ {%- set second_part = splitted[1:] | join('</think>') -%}
41
+ {%- set content = '<think> </think>' + second_part -%}
42
+ {%- endif %}
43
+ {%- endif %}
44
+ {{- '\n' + content + '<|eot_id|>' }}
45
+ {%- endif %}
46
+ {%- elif message.role == "assistant" %}
47
+ {{- '<|start_header_id|>' + message.role + '<|end_header_id|>\n' }}
48
+ {%- if message.content %}
49
+ {%- set content = message['content'] -%}
50
+ {%- if thinking %}
51
+ {%- if not keep_cots %}
52
+ {%- set splitted = content.split('</think>') -%}
53
+ {%- set second_part = splitted[1:] | join('</think>') -%}
54
+ {%- set content = '<think> </think>' + second_part -%}
55
+ {%- endif %}
56
+ {%- endif %}
57
+ {{- '\n' + content }}
58
+ {%- endif %}
59
+ {%- for tool_call in message.tool_calls %}
60
+ {%- if tool_call.function is defined %}
61
+ {%- set tool_call = tool_call.function %}
62
+ {%- endif %}
63
+ {{- '\n<tool_call>\n{"name": "' }}
64
+ {{- tool_call.name }}
65
+ {{- '", "arguments": ' }}
66
+ {{- tool_call.arguments | tojson }}
67
+ {{- '}\n</tool_call>' }}
68
+ {%- endfor %}
69
+ {{- '<|eot_id|>' }}
70
+ {%- elif message.role == "tool" %}
71
+ {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}
72
+ {{- '<|start_header_id|>user<|end_header_id|>\n' }}
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
+ {{- '<|eot_id|>' }}
79
+ {%- endif %}
80
+ {%- endif %}
81
+ {%- endfor %}
82
+ {%- if add_generation_prompt %}
83
+ {{- '<|start_header_id|>assistant<|end_header_id|>\n\n' }}
84
+ {%- endif %}
85
+ {#- Copyright 2025-present Unsloth. Apache 2.0 License. #}