qurk41 commited on
Commit
f20d412
·
verified ·
1 Parent(s): 028beef

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
+ {%- if tools %}
2
+ {{- '<|im_start|>system\n' }}
3
+ {%- if messages[0]['role'] == 'system' %}
4
+ {{- messages[0]['content'] }}
5
+ {%- else %}
6
+ {{- '' }}
7
+ {%- endif %}
8
+ {{- "\n\n# 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>" }}
9
+ {%- for tool in tools %}
10
+ {{- "\n" }}
11
+ {{- tool | tojson }}
12
+ {%- endfor %}
13
+ {{- "\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" }}
14
+ {%- else %}
15
+ {%- if messages[0]['role'] == 'system' %}
16
+ {{- '<|im_start|>system\n' + messages[0]['content'] + '<|im_end|>\n' }}
17
+ {%- else %}
18
+ {{- '<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n' }}
19
+ {%- endif %}
20
+ {%- endif %}
21
+ {%- for message in messages %}
22
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
23
+ {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
24
+ {%- elif message.role == "assistant" and not message.tool_calls %}
25
+ {%- set content = message.content %}
26
+ {%- if not loop.last %}
27
+ {%- set answer_blocks = message.content.split('<answer>\n') %}
28
+ {%- if answer_blocks|length > 1 %}
29
+ {%- set last_answer_block = answer_blocks[-1] %}
30
+ {%- if '\n</answer>' in last_answer_block %}
31
+ {%- set content = last_answer_block.split('\n</answer>')[0] %}
32
+ {%- else %}
33
+ {%- set content = message.content.split('<think_off>')[-1].lstrip('\n') %}
34
+ {%- set content = content.split('</think>')[-1].lstrip('\n') %}
35
+ {%- endif %}
36
+ {%- else %}
37
+ {%- set content = message.content.split('<think_off>')[-1].lstrip('\n') %}
38
+ {%- set content = content.split('</think>')[-1].lstrip('\n') %}
39
+ {%- endif %}
40
+ {%- endif %}
41
+ {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
42
+ {%- elif message.role == "assistant" %}
43
+ {%- set content = message.content %}
44
+ {%- if not loop.last %}
45
+ {%- set answer_blocks = message.content.split('<answer>\n') %}
46
+ {%- if answer_blocks|length > 1 %}
47
+ {%- set last_answer_block = answer_blocks[-1] %}
48
+ {%- if '\n</answer>' in last_answer_block %}
49
+ {%- set content = last_answer_block.split('\n</answer>')[0] %}
50
+ {%- else %}
51
+ {%- set content = message.content.split('<think_off>')[-1].lstrip('\n') %}
52
+ {%- set content = content.split('</think>')[-1].lstrip('\n') %}
53
+ {%- endif %}
54
+ {%- else %}
55
+ {%- set content = message.content.split('<think_off>')[-1].lstrip('\n') %}
56
+ {%- set content = content.split('</think>')[-1].lstrip('\n') %}
57
+ {%- endif %}
58
+ {%- endif %}
59
+ {{- '<|im_start|>' + message.role }}
60
+ {%- if message.content %}
61
+ {{- '\n' + content }}
62
+ {%- endif %}
63
+ {%- for tool_call in message.tool_calls %}
64
+ {%- if tool_call.function is defined %}
65
+ {%- set tool_call = tool_call.function %}
66
+ {%- endif %}
67
+ {{- '\n<tool_call>\n{\"name\": \"' }}
68
+ {{- tool_call.name }}
69
+ {{- '\", \"arguments\": ' }}
70
+ {{- tool_call.arguments | tojson }}
71
+ {{- '}\n</tool_call>' }}
72
+ {%- endfor %}
73
+ {{- '<|im_end|>\n' }}
74
+ {%- elif message.role == "tool" %}
75
+ {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}
76
+ {{- '<|im_start|>user' }}
77
+ {%- endif %}
78
+ {{- '\n<tool_response>\n' }}
79
+ {{- message.content }}
80
+ {{- '\n</tool_response>' }}
81
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
82
+ {{- '<|im_end|>\n' }}
83
+ {%- endif %}
84
+ {%- endif %}
85
+ {%- endfor %}
86
+ {%- if add_generation_prompt %}
87
+ {{- '<|im_start|>assistant\n<judge>\n' }}
88
+ {%- endif %}