MCPcopy Index your code
hub / github.com/abetlen/llama-cpp-python / format_chatml

Function format_chatml

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

Source from the content-addressed store, hash-verified

1341
1342@register_chat_format("chatml")
1343def format_chatml(
1344 messages: List[llama_types.ChatCompletionRequestMessage],
1345 **kwargs: Any,
1346) -> ChatFormatterResponse:
1347 system_template = """<|im_start|>system
1348{system_message}"""
1349 system_message = _get_system_message(messages)
1350 system_message = system_template.format(system_message=system_message)
1351 _roles = dict(user="<|im_start|>user", assistant="<|im_start|>assistant")
1352 _sep = "<|im_end|>"
1353 _messages = _map_roles(messages, _roles)
1354 _messages.append((_roles["assistant"], None))
1355 _prompt = _format_chatml(system_message, _messages, _sep)
1356 return ChatFormatterResponse(prompt=_prompt, stop=_sep)
1357
1358
1359@register_chat_format("mistral-instruct")

Callers

nothing calls this directly

Calls 6

_get_system_messageFunction · 0.85
_map_rolesFunction · 0.85
_format_chatmlFunction · 0.85
formatMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…