(
self,
*,
messages: List[ChatCompletionRequestMessage],
media_marker: Optional[str] = None,
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,
)
| 3677 | ) |
| 3678 | |
| 3679 | def format( |
| 3680 | self, |
| 3681 | *, |
| 3682 | messages: List[ChatCompletionRequestMessage], |
| 3683 | media_marker: Optional[str] = None, |
| 3684 | functions: Optional[List[ChatTemplateFunctionDefinition]] = None, |
| 3685 | function_call: Optional[Union[str, ChatTemplateFunctionCall]] = None, |
| 3686 | tools: Optional[List[ChatTemplateTool]] = None, |
| 3687 | tool_choice: Optional[Union[str, ChatTemplateToolChoice]] = None, |
| 3688 | reasoning_effort: Optional[str] = None, |
| 3689 | ) -> Tuple[str, str, List[str]]: |
| 3690 | render_time = datetime.now() |
| 3691 | |
| 3692 | def strftime_now(format_string: str) -> str: |
| 3693 | return render_time.strftime(format_string) |
| 3694 | |
| 3695 | chat_template = self._render( |
| 3696 | messages=messages, |
| 3697 | media_marker=media_marker, |
| 3698 | functions=functions, |
| 3699 | function_call=function_call, |
| 3700 | tools=tools, |
| 3701 | tool_choice=tool_choice, |
| 3702 | reasoning_effort=reasoning_effort, |
| 3703 | add_generation_prompt=False, |
| 3704 | strftime_now=strftime_now, |
| 3705 | ) |
| 3706 | prompt = self._render( |
| 3707 | messages=messages, |
| 3708 | media_marker=media_marker, |
| 3709 | functions=functions, |
| 3710 | function_call=function_call, |
| 3711 | tools=tools, |
| 3712 | tool_choice=tool_choice, |
| 3713 | reasoning_effort=reasoning_effort, |
| 3714 | add_generation_prompt=True, |
| 3715 | strftime_now=strftime_now, |
| 3716 | ) |
| 3717 | generation_prompt = prompt[len(chat_template) :] if prompt.startswith(chat_template) else "" |
| 3718 | stop = [self._eos_token] if self._eos_token else [] |
| 3719 | return prompt, generation_prompt, stop |
| 3720 | |
| 3721 | |
| 3722 | @dataclass |
no test coverage detected