(
self,
messages: List[ChatCompletionRequestMessage],
*,
functions: Optional[List[ChatTemplateFunctionDefinition]] = None,
function_call: Optional[Union[str, ChatTemplateFunctionCall]] = None,
tools: Optional[List[ChatTemplateTool]] = None,
tool_choice: Optional[Union[str, ChatTemplateToolChoice]] = None,
reasoning_effort: Optional[str] = None,
)
| 11990 | return bos_tokens + prefix_tokens + suffix_tokens + [self.fim_mid_token] + eos_tokens |
| 11991 | |
| 11992 | def build_chat_prompt( |
| 11993 | self, |
| 11994 | messages: List[ChatCompletionRequestMessage], |
| 11995 | *, |
| 11996 | functions: Optional[List[ChatTemplateFunctionDefinition]] = None, |
| 11997 | function_call: Optional[Union[str, ChatTemplateFunctionCall]] = None, |
| 11998 | tools: Optional[List[ChatTemplateTool]] = None, |
| 11999 | tool_choice: Optional[Union[str, ChatTemplateToolChoice]] = None, |
| 12000 | reasoning_effort: Optional[str] = None, |
| 12001 | ) -> Tuple[str, str, PromptPlan, List[str]]: |
| 12002 | if self.chat_formatter is None: |
| 12003 | raise ValueError("model does not provide a GGUF chat template") |
| 12004 | if self.mtmd_processor is not None: |
| 12005 | prompt_plan = self.mtmd_processor.build_prompt_plan( |
| 12006 | messages=messages, |
| 12007 | functions=functions, |
| 12008 | function_call=function_call, |
| 12009 | tools=tools, |
| 12010 | tool_choice=tool_choice, |
| 12011 | reasoning_effort=reasoning_effort, |
| 12012 | ) |
| 12013 | formatter_stop = [self.chat_formatter._eos_token] if self.chat_formatter._eos_token else [] |
| 12014 | return ( |
| 12015 | prompt_plan.text, |
| 12016 | prompt_plan.generation_prompt, |
| 12017 | prompt_plan, |
| 12018 | formatter_stop, |
| 12019 | ) |
| 12020 | prompt, generation_prompt, formatter_stop = self.chat_formatter.format( |
| 12021 | messages=messages, |
| 12022 | functions=functions, |
| 12023 | function_call=function_call, |
| 12024 | tools=tools, |
| 12025 | tool_choice=tool_choice, |
| 12026 | reasoning_effort=reasoning_effort, |
| 12027 | ) |
| 12028 | prompt_tokens = self.tokenize(prompt, add_bos=False, special=True) |
| 12029 | return ( |
| 12030 | prompt, |
| 12031 | generation_prompt, |
| 12032 | PromptPlan.from_tokens( |
| 12033 | prompt, |
| 12034 | prompt_tokens, |
| 12035 | generation_prompt=generation_prompt, |
| 12036 | ), |
| 12037 | formatter_stop, |
| 12038 | ) |
| 12039 | |
| 12040 | def detokenize(self, tokens: Sequence[int]) -> bytes: |
| 12041 | if not tokens: |
no test coverage detected