Python: Raise NotImplementedError for get_web_search_tool() on AzureOpenAICha…#4480
Python: Raise NotImplementedError for get_web_search_tool() on AzureOpenAICha…#4480max-montes wants to merge 1 commit intomicrosoft:mainfrom
Conversation
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Pull request overview
Prevents a known runtime failure when users attempt to enable web search with AzureOpenAIChatClient (Azure OpenAI Chat Completions), by failing fast at tool creation time and adding a regression test tied to #3629.
Changes:
- Override
AzureOpenAIChatClient.get_web_search_tool()to raiseNotImplementedErrorwith guidance on supported alternatives. - Add a unit regression test ensuring the method raises on Azure chat client usage.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
python/packages/core/agent_framework/azure/_chat_client.py |
Adds a get_web_search_tool() override that raises early with a clear message for unsupported Azure Chat Completions web search. |
python/packages/core/tests/azure/test_azure_chat_client.py |
Adds a regression test asserting the new NotImplementedError behavior. |
| ) | ||
|
|
||
| @staticmethod | ||
| def get_web_search_tool(**kwargs: Any) -> dict[str, Any]: |
There was a problem hiding this comment.
get_web_search_tool is overriding the OpenAI chat client factory method but uses a generic **kwargs signature. Consider matching the upstream signature (e.g., keyword-only web_search_options) so help()/docs/autocomplete stay consistent across clients and type-checkers can provide the expected parameter hints, even though this implementation always raises.
| def get_web_search_tool(**kwargs: Any) -> dict[str, Any]: | |
| def get_web_search_tool(*, web_search_options: Any | None = None) -> dict[str, Any]: |
| assert any(term in second_response.text.lower() for term in ["miami", "sunny", "72"]) | ||
|
|
||
|
|
||
| def test_get_web_search_tool_raises_not_implemented(azure_openai_unit_test_env: dict[str, str]) -> None: |
There was a problem hiding this comment.
This test requests the azure_openai_unit_test_env fixture but doesn’t use it. If the environment setup isn’t required for this assertion, consider removing the fixture parameter to keep the test focused and avoid unnecessary fixture setup.
| def test_get_web_search_tool_raises_not_implemented(azure_openai_unit_test_env: dict[str, str]) -> None: | |
| def test_get_web_search_tool_raises_not_implemented() -> None: |
…tClient Azure OpenAI's Chat Completions API does not support the web_search_options parameter. Previously, calling get_web_search_tool() on AzureOpenAIChatClient inherited the base OpenAI implementation, producing a config that caused a 400 error at runtime. Now raises NotImplementedError at tool creation time with a message directing users to OpenAIChatClient or AzureOpenAIResponsesClient. Fixes microsoft#3629 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
5bc21a2 to
fbd8eb5
Compare
Motivation and Context
Azure OpenAI's Chat Completions API does not support the web_search_options parameter. Previously, calling get_web_search_tool() on AzureOpenAIChatClient inherited the base OpenAI implementation, producing a config that caused a 400 error at runtime. Now raises NotImplementedError at tool creation time with a message directing users to OpenAIChatClient or AzureOpenAIResponsesClient.
Fixes #3629
Description
Contribution Checklist