Last active
January 10, 2024 17:04
-
-
Save data-niklas/108bcf161831942872d6cc7dbafd3eea to your computer and use it in GitHub Desktop.
llama-cpp-mistral-chat-format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@register_chat_format("mistral") | |
def format_mistral( | |
messages: List[llama_types.ChatCompletionRequestMessage], | |
**kwargs: Any, | |
) -> ChatFormatterResponse: | |
_prompt = "" | |
skip = False | |
for i, (message) in enumerate(messages): | |
role = message["role"] | |
content = message["content"] | |
if skip: | |
skip = False | |
continue | |
if i < len(messages) - 1: | |
next_role, next_content = messages[i+1]["role"], messages[i+1]["content"] | |
if next_role == "assistant": | |
_prompt += f"<s>[INST] {content} [/INST] {next_content}</s>" | |
skip = True | |
continue | |
if role == "system": | |
_prompt += f"<s>[INST] {content} [/INST] </s>" | |
else: | |
_prompt += f"[INST] {content} [/INST]" | |
#print(_prompt) | |
return ChatFormatterResponse(prompt=_prompt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment