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

Method _build_chat_formatter

examples/server/server.py:11912–11932  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

11910 return self._model_meta_value(self.llama_model, key)
11911
11912 def _build_chat_formatter(self) -> Optional[Jinja2ChatFormatter]:
11913 template_text = self.chat_template_override
11914 if template_text is None:
11915 template = llama_cpp.llama_model_chat_template(self.llama_model, None)
11916 if template:
11917 template_text = template.decode("utf-8", errors="ignore")
11918 if not template_text:
11919 return None
11920 bos_token = ""
11921 eos_token = ""
11922 if self.bos_token != -1:
11923 bos_text = llama_cpp.llama_vocab_get_text(self.vocab, self.bos_token)
11924 bos_token = bos_text.decode("utf-8", errors="ignore") if bos_text else ""
11925 if self.eos_token != -1:
11926 eos_text = llama_cpp.llama_vocab_get_text(self.vocab, self.eos_token)
11927 eos_token = eos_text.decode("utf-8", errors="ignore") if eos_text else ""
11928 return Jinja2ChatFormatter(
11929 template=template_text,
11930 bos_token=bos_token,
11931 eos_token=eos_token,
11932 )
11933
11934 def tokenize(
11935 self,

Callers 1

__init__Method · 0.95

Calls 2

Jinja2ChatFormatterClass · 0.70
decodeMethod · 0.45

Tested by

no test coverage detected