8000 Add chat format to support baichuan (#938) · abetlen/llama-cpp-python@4184835 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4184835

Browse files
authored
Add chat format to support baichuan (#938)
Signed-off-by: caiyesd <caiyesd@gmail.com>
1 parent 4474157 commit 4184835

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

llama_cpp/llama_chat_format.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,23 @@ def format_baichuan2(
471471
_prompt = _format_no_colon_single(system_message, _messages, _sep)
472472
return ChatFormatterResponse(prompt=_prompt)
473473

474+
475+
@register_chat_format("baichuan")
476+
def format_baichuan(
477+
messages: List[llama_types.ChatCompletionRequestMessage],
478+
**kwargs: Any,
479+
) -> ChatFormatterResponse:
480+
_system_template = "{system_message}"
481+
_roles = dict(user="<reserved_102>", assistant="<reserved_103>")
482+
_sep = ""
483+
system_message = _get_system_message(messages)
484+
system_message = _system_template.format(system_message=system_message)
485+
_messages = _map_roles(messages, _roles)
486+
_messages.append((_roles["assistant"], None))
487+
_prompt = _format_no_colon_single(system_message, _messages, _sep)
488+
return ChatFormatterResponse(prompt=_prompt)
489+
490+
474491
@register_chat_format("openbuddy")
475492
def format_openbuddy(
476493
messages: List[llama_types.ChatCompletionRequestMessage],

0 commit comments

Comments
 (0)
0