@@ -219,7 +219,6 @@ def parse_assistant_response(
219
219
class Qwen2Template (BaseTemplate ):
220
220
221
221
name = "qwen2"
222
- system_prompt = ""
223
222
allow_models = ["qwen2" ]
224
223
stop = {
225
224
"strings" : ["<|endoftext|>" , "<|im_end|>" ],
@@ -231,13 +230,17 @@ def template(self) -> str:
231
230
https://github.com/openai/openai-python/blob/main/chatml.md
232
231
"""
233
232
return (
234
- "{{ system_prompt }}"
235
233
"{% for message in messages %}"
236
- "{{ '<|im_start|>' + message['role'] + '\\ n' + message['content'] + '<|im_end|>' + '\\ n' }}"
237
- "{% endfor %}"
238
- "{% if add_generation_prompt %}"
239
- "{{ '<|im_start|>assistant\\ n' }}"
234
+ "{% if loop.first and messages[0]['role'] != 'system' %}"
235
+ "{{ '<|im_start|>system\n You are a helpful assistant<|im_end|>\n ' }}"
236
+ "{% endif %}"
237
+ "{{'<|im_start|>' + message['role'] + '\n ' + message['content']}}"
238
+ "{% if (loop.last and add_generation_prompt) or not loop.last %}"
239
+ "{{ '<|im_end|>' + '\n '}}"
240
240
"{% endif %}"
241
+ "{% endfor %}"
242
+ "{% if add_generation_prompt and messages[-1]['role'] != 'assistant' %}"
243
+ "{{ '<|im_start|>assistant\n ' }}{% endif %}"
241
244
)
242
245
243
246
@@ -1402,6 +1405,6 @@ def template(self) -> str:
1402
1405
{"role" : "assistant" , "content" : "I'm doing great. How can I help you today?" },
1403
1406
{"role" : "user" , "content" : "I'd like to show off how chat templating works!" },
1404
1407
]
1405
- template = get_prompt_adapter (prompt_name = "internlm2 " )
1408
+ template = get_prompt_adapter (prompt_name = "qwen2 " )
1406
1409
messages = template .postprocess_messages (chat )
1407
1410
print (template .apply_chat_template (messages ))
0 commit comments