8000 Add qwen chat format (#1005) · qeleb/llama-cpp-python@8b4db73 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8b4db73

Browse files
authored
Add qwen chat format (abetlen#1005)
1 parent 690c563 commit 8b4db73

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

llama_cpp/llama_chat_format.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,21 @@ def format_alpaca(
423423
_prompt = _format_add_colon_two(system_message, _messages, _sep, _sep2)
424424
return ChatFormatterResponse(prompt=_prompt)
425425

426+
@register_chat_format("qwen")
427+
def format_qwen(
428+
messages: List[llama_types.ChatCompletionRequestMessage],
429+
**kwargs: Any,
430+
) -> ChatFormatterResponse:
431+
_roles = dict(user="<|im_start|>user", assistant="<|im_start|>assistant")
432+
system_message="You are a helpful assistant."
433+
system_template="<|im_start|>system\n{system_message}"
434+
system_message=system_template.format(system_message=system_message)
435+
_messages = _map_roles(messages, _roles)
436+
_messages.append((_roles["assistant"], None))
437+
_sep = "<|im_end|>"
438+
_prompt = _format_chatml(system_message, _messages, _sep)
439+
_sep2 = "<|endoftext|>"
440+
return ChatFormatterResponse(prompt=_prompt,stop=_sep2)
426441

427442
@register_chat_format("vicuna")
428443
def format(

0 commit comments

Comments
 (0)
0