@@ -424,10 +424,15 @@ def system(self) -> str:
424424 """The model provider."""
425425 return self ._provider .name
426426
427- @classmethod
428- def supported_builtin_tools (cls ) -> frozenset [type [AbstractBuiltinTool ]]:
429- """Return the set of builtin tool types this model class can handle."""
430- return frozenset ({WebSearchTool })
427+ def supported_builtin_tools (self , profile : ModelProfile ) -> frozenset [type [AbstractBuiltinTool ]]:
428+ """Return the set of builtin tool types this model can handle.
429+
430+ WebSearchTool is only supported if openai_chat_supports_web_search is True.
431+ """
432+ openai_profile = OpenAIModelProfile .from_profile (profile )
433+ if openai_profile .openai_chat_supports_web_search :
434+ return frozenset ({WebSearchTool })
435+ return frozenset ()
431436
432437 @property
433438 @deprecated ('Set the `system_prompt_role` in the `OpenAIModelProfile` instead.' )
@@ -699,12 +704,6 @@ def _get_tools(self, model_request_parameters: ModelRequestParameters) -> list[c
699704 def _get_web_search_options (self , model_request_parameters : ModelRequestParameters ) -> WebSearchOptions | None :
700705 for tool in model_request_parameters .builtin_tools :
701706 if isinstance (tool , WebSearchTool ): # pragma: no branch
702- if not OpenAIModelProfile .from_profile (self .profile ).openai_chat_supports_web_search :
703- raise UserError (
704- f'WebSearchTool is not supported with `OpenAIChatModel` and model { self .model_name !r} . '
705- f'Please use `OpenAIResponsesModel` instead.'
706- )
707-
708707 if tool .user_location :
709708 return WebSearchOptions (
710709 search_context_size = tool .search_context_size ,
@@ -714,10 +713,7 @@ def _get_web_search_options(self, model_request_parameters: ModelRequestParamete
714713 ),
715714 )
716715 return WebSearchOptions (search_context_size = tool .search_context_size )
717- else :
718- raise UserError (
719- f'`{ tool .__class__ .__name__ } ` is not supported by `OpenAIChatModel`. If it should be, please file an issue.'
720- )
716+ return None
721717
722718 @dataclass
723719 class _MapModelResponseContext :
@@ -1096,9 +1092,8 @@ def system(self) -> str:
10961092 """The model provider."""
10971093 return self ._provider .name
10981094
1099- @classmethod
1100- def supported_builtin_tools (cls ) -> frozenset [type [AbstractBuiltinTool ]]:
1101- """Return the set of builtin tool types this model class can handle."""
1095+ def supported_builtin_tools (self , profile : ModelProfile ) -> frozenset [type [AbstractBuiltinTool ]]:
1096+ """Return the set of builtin tool types this model can handle."""
11021097 return frozenset ({WebSearchTool , CodeExecutionTool , MCPServerTool , ImageGenerationTool })
11031098
11041099 async def request (
0 commit comments