MCPcopy Create free account
hub / github.com/abetlen/llama-cpp-python / format_gemma

Function format_gemma

llama_cpp/llama_chat_format.py:1440–1454  ·  view source on GitHub ↗
(
    messages: List[llama_types.ChatCompletionRequestMessage],
    **kwargs: Any,
)

Source from the content-addressed store, hash-verified

1438# https://huggingface.co/collections/google/gemma-release-65d5efbccdbb8c4202ec078b
1439@register_chat_format("gemma")
1440def format_gemma(
1441 messages: List[llama_types.ChatCompletionRequestMessage],
1442 **kwargs: Any,
1443) -> ChatFormatterResponse:
1444 system_message = _get_system_message(messages)
1445 if system_message != "":
1446 logger.debug(
1447 "`role='system'` messages are not allowed on Google's Gemma models."
1448 )
1449 _roles = dict(user="<start_of_turn>user\n", assistant="<start_of_turn>model\n")
1450 _sep = "<end_of_turn>\n"
1451 _messages = _map_roles(messages, _roles)
1452 _messages.append((_roles["assistant"], None))
1453 _prompt = _format_no_colon_single(system_message="", messages=_messages, sep=_sep)
1454 return ChatFormatterResponse(prompt=_prompt, stop=_sep)
1455
1456
1457# Tricky chat formats that require custom chat handlers

Callers

nothing calls this directly

Calls 5

_get_system_messageFunction · 0.85
_map_rolesFunction · 0.85
_format_no_colon_singleFunction · 0.85
appendMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…