Skip to content

Commit c78a8a1

Browse files
authored
Update template.py
1 parent c02514c commit c78a8a1

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

api/adapter/template.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,31 @@ def parse_assistant_response(
216216
return output, None
217217

218218

219+
class Qwen2Template(BaseTemplate):
220+
221+
name = "qwen2"
222+
system_prompt = ""
223+
allow_models = ["qwen2"]
224+
stop = {
225+
"strings": ["<|endoftext|>", "<|im_end|>"],
226+
}
227+
228+
@property
229+
def template(self) -> str:
230+
""" This template formats inputs in the standard ChatML format. See
231+
https://github.com/openai/openai-python/blob/main/chatml.md
232+
"""
233+
return (
234+
"{{ system_prompt }}"
235+
"{% 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' }}"
240+
"{% endif %}"
241+
)
242+
243+
219244
class Llama2Template(BaseTemplate):
220245

221246
name = "llama2"
@@ -1354,6 +1379,7 @@ def template(self) -> str:
13541379
register_prompt_adapter(PhoenixTemplate)
13551380

13561381
register_prompt_adapter(QwenTemplate)
1382+
register_prompt_adapter(Qwen2Template)
13571383

13581384
register_prompt_adapter(StarChatTemplate)
13591385
register_prompt_adapter(SusChatTemplate)

0 commit comments

Comments
 (0)