From 0320de0f083fe000c4b4eb3923706bc0b289b1e0 Mon Sep 17 00:00:00 2001 From: Rafaelblsilva Date: Sat, 7 Oct 2023 10:02:55 -0300 Subject: [PATCH 1/3] Added mistral instruct chat format as "mistral" --- 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 9a09a28ee..6af89fb28 100644 --- a/llama_cpp/llama_chat_format.py +++ b/llama_cpp/llama_chat_format.py @@ -320,3 +320,19 @@ def format_chatml( _messages.append((_roles["assistant"], None)) _prompt = _format_chatml(system_message, _messages, _sep) return ChatFormatterResponse(prompt=_prompt) + + +@register_chat_format("mistral") +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) From 643d031e997493fc4212b1f48dded29b069193a0 Mon Sep 17 00:00:00 2001 From: Andrei Date: Mon, 29 Jan 2024 00:29:37 -0500 Subject: [PATCH 2/3] Fix stop sequence (merge issue) --- llama_cpp/llama_chat_format.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llama_cpp/llama_chat_format.py b/llama_cpp/llama_chat_format.py index fb71be68f..c5dffeadb 100644 --- a/llama_cpp/llama_chat_format.py +++ b/llama_cpp/llama_chat_format.py @@ -890,7 +890,7 @@ def format_mistral( _messages = _map_roles(messages, _roles) _messages.append((_roles["assistant"], None)) _prompt = _format_no_colon_single(system_message, _messages, _sep) - return ChatFormatterResponse(prompt=_prompt, stop=_sep) + return ChatFormatterResponse(prompt=_prompt) @register_chat_format("chatglm3") From b3b6c19b2349e71506e8c909b42a766da136abcc Mon Sep 17 00:00:00 2001 From: Andrei Date: Mon, 29 Jan 2024 00:33:49 -0500 Subject: [PATCH 3/3] Update chat format name to `mistral-instruct` --- llama_cpp/llama_chat_format.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llama_cpp/llama_chat_format.py b/llama_cpp/llama_chat_format.py index c5dffeadb..989275a27 100644 --- a/llama_cpp/llama_chat_format.py +++ b/llama_cpp/llama_chat_format.py @@ -877,7 +877,7 @@ def format_chatml( return ChatFormatterResponse(prompt=_prompt, stop=_sep) -@register_chat_format("mistral") +@register_chat_format("mistral-instruct") def format_mistral( messages: List[llama_types.ChatCompletionRequestMessage], **kwargs: Any,