基于.NET构建聊天机器人调用Azure AI Search Index时遇HTTP 400错误求助
解决Azure OpenAI On Your Data视觉增强相关的HTTP 400错误
问题诊断
错误提示「The deployed GPT model does not support Vision Enhancement and On Your Data (OYD) with images」,核心原因是当前使用的GPT部署模型类型不匹配,或客户端配置中存在与视觉相关的隐式设置——即使你的索引仅包含文本数据,这类不匹配也会触发报错。
解决方案
1. 更换为纯文本GPT模型部署
确保Azure OpenAI中部署的是纯文本模型,而非带视觉能力的模型(如gpt-4-vision-preview)。推荐使用的纯文本模型包括:
gpt-35-turbogpt-4gpt-35-turbo-16k
2. 清理客户端配置中的视觉相关参数
检查ChatCompletionOptions及数据源配置,确保未启用任何图像相关设置:
- 确认
_chatClient初始化时指向的是纯文本模型的部署名称 - 确保
AzureSearchChatDataSource中未配置ImageFields等图像专属属性(你的索引无图像数据,无需此类配置)
3. 验证API与SDK版本兼容性
使用2024-02-15-preview及以上的Azure OpenAI API版本,同时将.NET SDK更新至最新稳定版,避免因版本差异导致的功能不兼容问题。
4. 修正代码中的同步调用问题
若使用较新版本的SDK,建议将同步的CompleteChat替换为异步方法CompleteChatAsync,符合.NET异步编程规范:
#pragma warning disable AOAI001 public async Task<string> SearchIndex(string IndexName, string prompt) { _searchClient = _searchIndexClient.GetSearchClient(IndexName); var options = new ChatCompletionOptions(); options.AddDataSource(new AzureSearchChatDataSource() { Endpoint = new Uri(_searchEndpoint), IndexName = IndexName, Authentication = DataSourceAuthentication.FromApiKey(_searchKey), InScope = true, // 确保未设置任何图像相关属性 }); try { // 改用异步调用方法 ChatCompletion completion = await _chatClient.CompleteChatAsync([new UserChatMessage(prompt)], options); AzureChatMessageContext onYourDataContext = completion.GetAzureMessageContext(); if (onYourDataContext?.Intent is not null) { Console.WriteLine($"Intent: {onYourDataContext.Intent}"); } foreach (AzureChatCitation citation in onYourDataContext?.Citations ?? []) { Console.WriteLine($"Citation: {citation.Content}"); } return completion.Content[0].Text; } catch (Exception ex) { Console.WriteLine(ex.Message.ToString()); return ex.Message.ToString(); } }
验证步骤
- 登录Azure门户,确认OpenAI部署的模型为纯文本类型
- 更新SDK版本后重启应用,重新测试调用
- 若仍报错,检查客户端初始化代码,确认未关联视觉模型部署
内容的提问来源于stack exchange,提问作者Hamza Zouaki
相关产品推荐
相关产品推荐

