From 3d93c856ba45f2ba53b4deffbc8240a2394f6b49 Mon Sep 17 00:00:00 2001 From: paulhshort Date: Mon, 11 Aug 2025 20:07:19 -0400 Subject: [PATCH] Fix Azure OpenAI web_search_preview tool incompatibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Azure OpenAI doesn't support the web_search_preview tool, which was causing "Hosted tool 'web_search_preview' is not supported" errors with GPT-5 models. ## Changes: - Pass dialect information to aixToOpenAIResponses function - Skip web_search_preview tool addition when dialect is 'azure' - Add logging when web search is skipped for Azure - Document known Azure limitations in implementation guide ## Impact: - Fixes web browsing errors with Azure GPT-5 models - Maintains web search functionality for regular OpenAI models - Provides clear logging for debugging This is a critical fix for Azure OpenAI compatibility as web search is not currently supported on Azure's Responses API implementation. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- docs/azure-openai-fix-implementation.md | 29 +++++++++++++++---- .../adapters/openai.responsesCreate.ts | 13 +++++++-- .../chatGenerate/chatGenerate.dispatch.ts | 2 +- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/docs/azure-openai-fix-implementation.md b/docs/azure-openai-fix-implementation.md index b4f63e361..d684d8386 100644 --- a/docs/azure-openai-fix-implementation.md +++ b/docs/azure-openai-fix-implementation.md @@ -113,14 +113,33 @@ Tested with Azure OpenAI endpoint `https://grid4openai.openai.azure.com`: 3. Add console logging is included to debug which API paradigm is being used 4. Environment variables provide full control over API versions and paradigms +## Known Limitations + +### Azure OpenAI Specific Limitations + +1. **Web Search Tool**: Azure OpenAI doesn't currently support the `web_search_preview` tool + - The fix automatically disables web search for Azure deployments + - Logs when web search is skipped: `[Azure] Skipping web_search_preview tool - not supported on Azure OpenAI` + - This affects all Azure models using the Responses API (GPT-5, o-series) + +2. **GPT-5 Model Constraints**: + - No temperature control (only default value of 1.0 supported) + - Must use `max_completion_tokens` instead of `max_tokens` + - These constraints are already handled in the existing code + +3. **Image Generation**: Multi-turn editing and streaming not yet supported on Azure + +4. **File Upload**: Images can't be uploaded as files and referenced as input (coming soon) + ## Benefits 1. **Fixes Issue #828**: Resolves "Resource Not Found" errors for GPT-5 and o3 Pro models -2. **Future-Proof**: Supports Azure's next-generation v1 API -3. **Backward Compatible**: Maintains support for existing deployments -4. **Robust**: Prevents malformed URLs from client misconfigurations -5. **Configurable**: Full control over API paradigms and versions -6. **Debuggable**: Includes logging for troubleshooting +2. **Handles Azure Limitations**: Automatically disables unsupported features like web search +3. **Future-Proof**: Supports Azure's next-generation v1 API +4. **Backward Compatible**: Maintains support for existing deployments +5. **Robust**: Prevents malformed URLs from client misconfigurations +6. **Configurable**: Full control over API paradigms and versions +7. **Debuggable**: Includes logging for troubleshooting ## Technical Details diff --git a/src/modules/aix/server/dispatch/chatGenerate/adapters/openai.responsesCreate.ts b/src/modules/aix/server/dispatch/chatGenerate/adapters/openai.responsesCreate.ts index 5d639d5ce..371c5d8ca 100644 --- a/src/modules/aix/server/dispatch/chatGenerate/adapters/openai.responsesCreate.ts +++ b/src/modules/aix/server/dispatch/chatGenerate/adapters/openai.responsesCreate.ts @@ -3,6 +3,7 @@ import { OpenAIWire_API_Responses, OpenAIWire_Responses_Items, OpenAIWire_Respon import { approxDocPart_To_String } from './anthropic.messageCreate'; import { aixDocPart_to_OpenAITextContent, aixMetaRef_to_OpenAIText, aixTexts_to_OpenAIInstructionText } from '~/modules/aix/server/dispatch/chatGenerate/adapters/openai.chatCompletions'; +import type { OpenAIDialects } from '~/modules/llms/server/openai/openai.router'; // configuration @@ -21,7 +22,7 @@ type TRequestTool = OpenAIWire_Responses_Tools.Tool; * - much side functionality is not implemented yet * - testing with o3-pro only for now */ -export function aixToOpenAIResponses(model: AixAPI_Model, chatGenerate: AixAPIChatGenerate_Request, jsonOutput: boolean, streaming: boolean): TRequest { +export function aixToOpenAIResponses(openAIDialect: OpenAIDialects | null, model: AixAPI_Model, chatGenerate: AixAPIChatGenerate_Request, jsonOutput: boolean, streaming: boolean): TRequest { // [OpenAI] Vendor-specific model checks const isOpenAIOFamily = ['gpt-6', 'gpt-5', 'o4', 'o3', 'o1'].some(_id => model.id === _id || model.id.startsWith(_id + '-')); @@ -95,8 +96,16 @@ export function aixToOpenAIResponses(model: AixAPI_Model, chatGenerate: AixAPICh // Tool: Search: for search models, and deep research models // NOTE: OpenAI doesn't support web search with minimal reasoning effort + // NOTE: Azure OpenAI doesn't support web search tool yet (as of Aug 2025) const skipWebSearchDueToMinimalReasoning = model.vndOaiReasoningEffort === 'minimal'; - if ((hotFixForceSearchTool || model.vndOaiWebSearchContext || model.userGeolocation) && !skipWebSearchDueToMinimalReasoning) { + const skipWebSearchDueToAzure = openAIDialect === 'azure'; + + // Log when web search is being skipped for Azure + if ((hotFixForceSearchTool || model.vndOaiWebSearchContext || model.userGeolocation) && skipWebSearchDueToAzure) { + console.log('[Azure] Skipping web_search_preview tool - not supported on Azure OpenAI'); + } + + if ((hotFixForceSearchTool || model.vndOaiWebSearchContext || model.userGeolocation) && !skipWebSearchDueToMinimalReasoning && !skipWebSearchDueToAzure) { if (!payload.tools?.length) payload.tools = []; const webSearchTool: TRequestTool = { diff --git a/src/modules/aix/server/dispatch/chatGenerate/chatGenerate.dispatch.ts b/src/modules/aix/server/dispatch/chatGenerate/chatGenerate.dispatch.ts index 6374d6d81..7485b70c8 100644 --- a/src/modules/aix/server/dispatch/chatGenerate/chatGenerate.dispatch.ts +++ b/src/modules/aix/server/dispatch/chatGenerate/chatGenerate.dispatch.ts @@ -101,7 +101,7 @@ export function createChatGenerateDispatch(access: AixAPI_Access, model: AixAPI_ return { request: { ...openAIAccess(access, model.id, '/v1/responses'), - body: aixToOpenAIResponses(model, chatGenerate, false, streaming), + body: aixToOpenAIResponses(access.dialect, model, chatGenerate, false, streaming), }, demuxerFormat: streaming ? 'fast-sse' : null, chatGenerateParse: streaming ? createOpenAIResponsesEventParser() : createOpenAIResponseParserNS(),