roskosmos19 commited on
Commit
68f1180
Β·
verified Β·
1 Parent(s): 1227828

Update chat_template.jinja

Browse files
Files changed (1) hide show
  1. chat_template.jinja +51 -16
chat_template.jinja CHANGED
@@ -1,19 +1,24 @@
1
  {%- if tools %}
2
- {{- '<|im_start|>system\n' }}
3
  {%- if messages[0].role == 'system' %}
4
  {{- messages[0].content + '\n\n' }}
 
 
5
  {%- endif %}
6
- {{- "# 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>" }}
7
  {%- for tool in tools %}
8
  {{- "\n" }}
9
  {{- tool | tojson }}
10
  {%- endfor %}
11
- {{- "\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" }}
12
  {%- else %}
13
  {%- if messages[0].role == 'system' %}
14
- {{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
 
 
15
  {%- endif %}
16
  {%- endif %}
 
17
  {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
18
  {%- for message in messages[::-1] %}
19
  {%- set index = (messages|length - 1) - loop.index0 %}
@@ -22,33 +27,60 @@
22
  {%- set ns.last_query_index = index %}
23
  {%- endif %}
24
  {%- endfor %}
 
25
  {%- for message in messages %}
26
  {%- if message.content is string %}
27
  {%- set content = message.content %}
28
  {%- else %}
29
  {%- set content = '' %}
30
  {%- endif %}
 
31
  {%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
32
- {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }}
 
33
  {%- elif message.role == "assistant" %}
34
  {%- set reasoning_content = '' %}
35
  {%- if message.reasoning_content is string %}
36
  {%- set reasoning_content = message.reasoning_content %}
37
  {%- else %}
38
- {%- if '</think>' in content %}
39
- {%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
40
- {%- set content = content.split('</think>')[-1].lstrip('\n') %}
41
  {%- endif %}
42
  {%- endif %}
 
43
  {%- if loop.index0 > ns.last_query_index %}
44
  {%- if loop.last or (not loop.last and reasoning_content) %}
45
- {{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  {%- else %}
47
- {{- '<|im_start|>' + message.role + '\n' + content }}
48
  {%- endif %}
49
  {%- else %}
50
- {{- '<|im_start|>' + message.role + '\n' + content }}
51
  {%- endif %}
 
52
  {%- if message.tool_calls %}
53
  {%- for tool_call in message.tool_calls %}
54
  {%- if (loop.first and content) or (not loop.first) %}
@@ -68,19 +100,22 @@
68
  {{- '}\n</tool_call>' }}
69
  {%- endfor %}
70
  {%- endif %}
71
- {{- '<|im_end|>\n' }}
 
72
  {%- elif message.role == "tool" %}
73
  {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
74
- {{- '<|im_start|>user' }}
75
  {%- endif %}
76
- {{- '\n<tool_response>\n' }}
77
  {{- content }}
78
  {{- '\n</tool_response>' }}
79
  {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
80
- {{- '<|im_end|>\n' }}
81
  {%- endif %}
82
  {%- endif %}
83
  {%- endfor %}
 
84
  {%- if add_generation_prompt %}
85
- {{- '<|im_start|>assistant\n<think>\n' }}
 
86
  {%- endif %}
 
1
  {%- if tools %}
2
+ {{- '||<|<|im_start|>system\n' }}
3
  {%- if messages[0].role == 'system' %}
4
  {{- messages[0].content + '\n\n' }}
5
+ {%- else %}
6
+ {{- 'You are Rhea-4B, a coding AI with multi-pass processing. Your process: 1) First implementation, 2) Self-review for bugs/edge cases/security/performance, 3) Final optimized version. Functionality remains identical, only structure and comments are improved.\n\n' }}
7
  {%- endif %}
8
+ {{- "# 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> ζ€θ€ƒη»“ζŸ\n" }}
14
  {%- else %}
15
  {%- if messages[0].role == 'system' %}
16
+ {{- '||<|<|im_start|>system\n' + messages[0].content + ' ζ€θ€ƒη»“ζŸ\n' }}
17
+ {%- else %}
18
+ {{- '||<|<|im_start|>system\nYou are Rhea-4B, a coding AI with multi-pass processing. Your process: 1) First implementation, 2) Self-review for bugs/edge cases/security/performance, 3) Final optimized version. Functionality remains identical, only structure and comments are improved. ζ€θ€ƒη»“ζŸ\n' }}
19
  {%- endif %}
20
  {%- endif %}
21
+
22
  {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
23
  {%- for message in messages[::-1] %}
24
  {%- set index = (messages|length - 1) - loop.index0 %}
 
27
  {%- set ns.last_query_index = index %}
28
  {%- endif %}
29
  {%- endfor %}
30
+
31
  {%- for message in messages %}
32
  {%- if message.content is string %}
33
  {%- set content = message.content %}
34
  {%- else %}
35
  {%- set content = '' %}
36
  {%- endif %}
37
+
38
  {%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
39
+ {{- '||<|<|im_start|>' + message.role + '\n' + content + ' ζ€θ€ƒη»“ζŸ\n' }}
40
+
41
  {%- elif message.role == "assistant" %}
42
  {%- set reasoning_content = '' %}
43
  {%- if message.reasoning_content is string %}
44
  {%- set reasoning_content = message.reasoning_content %}
45
  {%- else %}
46
+ {%- if 'ζ€θ€ƒη»“ζŸ' in content %}
47
+ {%- set reasoning_content = content.split('ζ€θ€ƒη»“ζŸ')[0].rstrip('\n').split('思考')[0].lstrip('\n') %}
48
+ {%- set content = content.split('ζ€θ€ƒη»“ζŸ')[-1].lstrip('\n') %}
49
  {%- endif %}
50
  {%- endif %}
51
+
52
  {%- if loop.index0 > ns.last_query_index %}
53
  {%- if loop.last or (not loop.last and reasoning_content) %}
54
+ {{- '||<|<|im_start|>' + message.role + '\n' }}
55
+
56
+ {# Multi-Pass Coding Structure #}
57
+ {{- '### PASS 1 - First Implementation:\n' }}
58
+ {{- content.lstrip('\n') }}
59
+
60
+ {{- '\n\n<<||<|<|think_start|>\n' }}
61
+ {{- '### PASS 2 - Self-Review:\n' }}
62
+ {{- '- Syntax errors? Check correct bracketing, semicolons, imports\n' }}
63
+ {{- '- Edge cases? Empty inputs, null values, boundary cases\n' }}
64
+ {{- '- Performance? Time complexity, memory leaks, loops\n' }}
65
+ {{- '- Security? SQL injection, XSS, buffer overflow, input validation\n' }}
66
+ {{- '- Type safety? Type hints, generics, null safety\n' }}
67
+ {{- '<||<|<|think_end|>\n' }}
68
+
69
+ {{- '\n<<||<|<|review_start|>\n' }}
70
+ {{- 'Review results: [Document found issues here]\n' }}
71
+ {{- '<||<|<|review_end|>\n' }}
72
+
73
+ {{- '\n<<||<|<|final_start|>\n' }}
74
+ {{- '### PASS 3 - Final Version:\n' }}
75
+ {{- 'Based on review - identical functionality, optimized structure:\n\n' }}
76
+
77
  {%- else %}
78
+ {{- '||<|<|im_start|>' + message.role + '\n' + content }}
79
  {%- endif %}
80
  {%- else %}
81
+ {{- '||<|<|im_start|>' + message.role + '\n' + content }}
82
  {%- endif %}
83
+
84
  {%- if message.tool_calls %}
85
  {%- for tool_call in message.tool_calls %}
86
  {%- if (loop.first and content) or (not loop.first) %}
 
100
  {{- '}\n</tool_call>' }}
101
  {%- endfor %}
102
  {%- endif %}
103
+ {{- ' ζ€θ€ƒη»“ζŸ\n' }}
104
+
105
  {%- elif message.role == "tool" %}
106
  {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
107
+ {{- '||<|<|im_start|>user' }}
108
  {%- endif %}
109
+ {{- '\n<<tool_response>\n' }}
110
  {{- content }}
111
  {{- '\n</tool_response>' }}
112
  {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
113
+ {{- ' ζ€θ€ƒη»“ζŸ\n' }}
114
  {%- endif %}
115
  {%- endif %}
116
  {%- endfor %}
117
+
118
  {%- if add_generation_prompt %}
119
+ {{- '||<|<|im_start|>assistant\n' }}
120
+ {{- '### PASS 1 - First Implementation:\n' }}
121
  {%- endif %}