Skip to content

Instantly share code, notes, and snippets.

@data-niklas
Last active January 10, 2024 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save data-niklas/108bcf161831942872d6cc7dbafd3eea to your computer and use it in GitHub Desktop.
Save data-niklas/108bcf161831942872d6cc7dbafd3eea to your computer and use it in GitHub Desktop.
llama-cpp-mistral-chat-format
@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