调用ChatClient.CompleteChat()遇400错误,Azure RAG服务故障排查求助
基于Azure的RAG聊天服务突发HTTP 400错误(ASP.NET Core 8 + Azure.AI.OpenAI 2.1.0)
上周晚些时候,我们基于Azure搭建的RAG聊天服务开始返回HTTP 400 Bad Request错误。Web API运行在ASP.NET Core 8上,代码未做任何变更,且已确认代码符合Azure.AI.OpenAI 2.1.0的示例规范。
已尝试以下排查步骤:
- 重新生成搜索服务及OpenAI服务的API密钥
- 重新创建Azure Search索引、索引器、技能集和数据源
- 在Stack Overflow和Microsoft问答平台搜索解决方案
- 使用Fiddler和Wireshark检查数据包
求指出错误原因或提供新的排查方向。
调用CompleteChat()的代码片段(端点和API密钥变量值已确认正确):
[Authorize] [HttpPost] public ActionResult<string> Post([FromBody] string userMessage) { try { AzureOpenAIClient client = new AzureOpenAIClient( new Uri(azureOpenAIEndpoint), new ApiKeyCredential(azureOpenAIKey) ); ChatClient chatClient = client.GetChatClient(deploymentName); ChatCompletionOptions chatOptions = new ChatCompletionOptions() { MaxOutputTokenCount = 4096, ResponseFormat = ChatResponseFormat.CreateJsonObjectFormat(), Temperature = 0.1f }; chatOptions.AddDataSource(new AzureSearchChatDataSource() { Authentication = DataSourceAuthentication.FromApiKey(searchKey), Endpoint = new Uri(searchEndpoint), IndexName = searchIndex }); ChatCompletion chatCompletion = chatClient.CompleteChat([ new SystemChatMessage(systemPrompt), new UserChatMessage(userMessage) ], chatOptions); return Ok(chatCompletion.Content[0].Text); } catch (Exception ex) { var result = StatusCode(StatusCodes.Status500InternalServerError, new { Message = ex.Message }); return result; } }
更新:刚发现AzureSearchChatDataSource类已被标记为过时,推测微软可能已移除相关功能。目前考虑切换至Semantic Kernel,求其他可行解决方案。
内容的提问来源于stack exchange,提问作者WhosOnFirst
相关产品推荐
相关产品推荐

