Osaurus-AI commited on
Commit
fd24fda
·
verified ·
1 Parent(s): 6e4985f

Upload chat_template.jinja with huggingface_hub

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