From ce38dbdf0730aa2fb3a659e0a5bda2e8ad07da17 Mon Sep 17 00:00:00 2001 From: Rafaelblsilva Date: Mon, 29 Jan 2024 02:34:42 -0300 Subject: [PATCH] Add mistral instruct chat format as "mistral-instruct" (#799) * Added mistral instruct chat format as "mistral" * Fix stop sequence (merge issue) * Update chat format name to `mistral-instruct` --------- Co-authored-by: Andrei --- llama_cpp/llama_chat_format.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/llama_cpp/llama_chat_format.py b/llama_cpp/llama_chat_format.py index e418d40..989275a 100644 --- a/llama_cpp/llama_chat_format.py +++ b/llama_cpp/llama_chat_format.py @@ -877,6 +877,22 @@ def format_chatml( return ChatFormatterResponse(prompt=_prompt, stop=_sep) +@register_chat_format("mistral-instruct") +def format_mistral( + messages: List[llama_types.ChatCompletionRequestMessage], + **kwargs: Any, +) -> ChatFormatterResponse: + _roles = dict(user="[INST] ", assistant="[/INST]") + _sep = " " + system_template = """{system_message}""" + system_message = _get_system_message(messages) + system_message = system_template.format(system_message=system_message) + _messages = _map_roles(messages, _roles) + _messages.append((_roles["assistant"], None)) + _prompt = _format_no_colon_single(system_message, _messages, _sep) + return ChatFormatterResponse(prompt=_prompt) + + @register_chat_format("chatglm3") def format_chatglm3( messages: List[llama_types.ChatCompletionRequestMessage],