Python: Fix HostedWebSearchTool failing with AzureOpenAIChatClient#3876
Open
hashwnath wants to merge 2 commits intomicrosoft:mainfrom
Open
Python: Fix HostedWebSearchTool failing with AzureOpenAIChatClient#3876hashwnath wants to merge 2 commits intomicrosoft:mainfrom
hashwnath wants to merge 2 commits intomicrosoft:mainfrom
Conversation
…#3629) Override _prepare_tools_for_openai() in AzureOpenAIChatClient to raise ServiceInvalidRequestError when web search tools are used, since Azure OpenAI's Chat Completions API does not support the web_search_options parameter. Fixes microsoft#3629
Changed _prepare_tools_for_openai to filter out unsupported web search tools and log a warning, rather than raising ServiceInvalidRequestError. This ensures that requests with multiple tools don't fail entirely just because a web search tool was included.
Author
|
@microsoft-github-policy-service agree [company="{MAQ Software(Microsoft Partner)}"] |
|
@hashwnath the command you issued was incorrect. Please try again. Examples are: and |
Author
|
@microsoft-github-policy-service agree company="MAQ Software" |
| ) | ||
|
|
||
| @override | ||
| def _prepare_tools_for_openai(self, tools: Sequence[Any]) -> dict[str, Any]: |
Member
There was a problem hiding this comment.
thanks for looking into this, however we also should have the:
@staticmethod
def get_web_search_tool(
*,
web_search_options: WebSearchOptions | None = None,
) -> dict[str, Any]:raise a NotSupportedError in the azure chat client so that people do not switch from OpenAI to Azure OpenAI and keep that in.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
Fixes #3629
AzureOpenAIChatClientinherits_prepare_tools_for_openai()fromRawOpenAIChatClient, which extracts web search tools into a top-levelweb_search_optionsparameter. Azure OpenAI's Chat Completions API does not support this parameter (it's OpenAI-only), resulting in:Description
Override
_prepare_tools_for_openai()inAzureOpenAIChatClientto gracefully filter out web search tools and log a warning, rather than letting the request fail.This ensures robust handling: requests with multiple tools (e.g., weather + web search) will still succeed for the supported tools, while the user is clearly warned that web search is not supported on this endpoint. The warning directs users to use
OpenAIChatClientorAzureOpenAIResponsesClientif web search is required.Changes
azure/_chat_client.py: Added_prepare_tools_for_openai()override that filters out{"type": "web_search"}tools and logs a warningtests/azure/test_azure_chat_client.py: Added tests verifying that web search tools are filtered out with a warning and that normal tools are preservedContribution Checklist