Skip to content

Commit

Permalink
Add mistral instruct chat format as "mistral-instruct" (#799)
Browse files Browse the repository at this point in the history
* Added mistral instruct chat format as "mistral"

* Fix stop sequence (merge issue)

* Update chat format name to `mistral-instruct`

---------

Co-authored-by: Andrei <abetlen@gmail.com>
  • Loading branch information
Rafaelblsilva and abetlen authored Jan 29, 2024
1 parent 52c4a84 commit ce38dbd
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions llama_cpp/llama_chat_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """<s>{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],
Expand Down

0 comments on commit ce38dbd

Please sign in to comment.