Skip to content

Add user-assistant chat format #1281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions llama_cpp/llama_chat_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,23 @@ def format_gemma(
return ChatFormatterResponse(prompt=_prompt, stop=_sep)


# Chat format for Nous-Capybara models, see more details:
# https://huggingface.co/NousResearch/Nous-Capybara-34B
@register_chat_format("user-assistant")
def format_user_assistant(
messages: List[llama_types.ChatCompletionRequestMessage],
**kwargs: Any,
) -> ChatFormatterResponse:
stop_str = "</s>"
system_message = _get_system_message(messages)
_roles = dict(user="USER:", assistant="ASSISTANT:")
_sep = "\n"
_messages = _map_roles(messages, _roles)
_messages.append((_roles["assistant"], None))
_prompt = _format_chatml(system_message, _messages, _sep)
return ChatFormatterResponse(prompt=_prompt, stop=stop_str)


# Tricky chat formats that require custom chat handlers


Expand Down