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

Function format_llama2

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

Source from the content-addressed store, hash-verified

1048# system prompt is "embedded" in the first message
1049@register_chat_format("llama-2")
1050def format_llama2(
1051 messages: List[llama_types.ChatCompletionRequestMessage],
1052 **kwargs: Any,
1053) -> ChatFormatterResponse:
1054 _system_template = "[INST] <<SYS>>\n{system_message}\n<</SYS>>"
1055 _roles = dict(user="<s>[INST]", assistant="[/INST]")
1056 _messages = _map_roles(messages, _roles)
1057 system_message = _get_system_message(messages)
1058 if system_message:
1059 system_message = _system_template.format(system_message=system_message)
1060 _prompt = _format_llama2(system_message, _messages, " ", "</s>") + "[/INST]"
1061 return ChatFormatterResponse(prompt=_prompt)
1062
1063
1064# Chat format for Llama-3 models, see more details at:

Callers

nothing calls this directly

Calls 5

_map_rolesFunction · 0.85
_get_system_messageFunction · 0.85
_format_llama2Function · 0.85
formatMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…