(
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,
)
| 10957 | return positions.reshape(-1) |
| 10958 | |
| 10959 | def build_prompt_plan( |
| 10960 | self, |
| 10961 | *, |
| 10962 | messages: List[ChatCompletionRequestMessage], |
| 10963 | functions: Optional[List[ChatTemplateFunctionDefinition]] = None, |
| 10964 | function_call: Optional[Union[str, ChatTemplateFunctionCall]] = None, |
| 10965 | tools: Optional[List[ChatTemplateTool]] = None, |
| 10966 | tool_choice: Optional[Union[str, ChatTemplateToolChoice]] = None, |
| 10967 | reasoning_effort: Optional[str] = None, |
| 10968 | ) -> PromptPlan: |
| 10969 | media_inputs = Jinja2ChatFormatter.media_inputs_from_messages(messages) |
| 10970 | if not media_inputs: |
| 10971 | prompt, generation_prompt, _ = self.chat_formatter.format( |
| 10972 | messages=messages, |
| 10973 | functions=functions, |
| 10974 | function_call=function_call, |
| 10975 | tools=tools, |
| 10976 | tool_choice=tool_choice, |
| 10977 | reasoning_effort=reasoning_effort, |
| 10978 | ) |
| 10979 | tokens = self.tokenize(prompt, add_bos=False, special=True) |
| 10980 | return PromptPlan.from_tokens(prompt, tokens, generation_prompt=generation_prompt) |
| 10981 | if any(media.kind == "image" for media in media_inputs) and not self.supports_vision: |
| 10982 | raise CompletionRequestValidationError("MTMD projector does not support images") |
| 10983 | if any(media.kind == "audio" for media in media_inputs) and not self.supports_audio: |
| 10984 | raise CompletionRequestValidationError("MTMD projector does not support audio") |
| 10985 | if any(media.kind == "video" for media in media_inputs) and not self.supports_video: |
| 10986 | raise CompletionRequestValidationError("MTMD projector does not support video") |
| 10987 | with self.lock: |
| 10988 | return self._build_prompt_plan_locked( |
| 10989 | messages=messages, |
| 10990 | media_inputs=media_inputs, |
| 10991 | functions=functions, |
| 10992 | function_call=function_call, |
| 10993 | tools=tools, |
| 10994 | tool_choice=tool_choice, |
| 10995 | reasoning_effort=reasoning_effort, |
| 10996 | ) |
| 10997 | |
| 10998 | def _build_prompt_plan_locked( |
| 10999 | self, |
no test coverage detected