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

Function _format_llama2

llama_cpp/llama_chat_format.py:902–916  ·  view source on GitHub ↗

Format the prompt with the llama2 style.

(
    system_message: str, messages: List[Tuple[str, Optional[str]]], sep: str, sep2: str
)

Source from the content-addressed store, hash-verified

900
901
902def _format_llama2(
903 system_message: str, messages: List[Tuple[str, Optional[str]]], sep: str, sep2: str
904) -> str:
905 """Format the prompt with the llama2 style."""
906 seps = [sep, sep2]
907 ret = system_message + sep
908 for i, (role, message) in enumerate(messages):
909 if system_message and i == 0:
910 m = message or ""
911 ret += m + seps[i % 2]
912 elif message:
913 ret += role + message + " " + seps[i % 2]
914 else:
915 ret += role + " "
916 return ret
917
918
919def _format_add_colon_single(

Callers 1

format_llama2Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…