欧博官网Azure ai throwing service request failed error

I upload same file on the azure portal and try it there seems returning correct result.

Portal provides search results as "context" in the prompt. So, Here AI model is primed with relevant data to answer the question accurately.

When you pass the search results manually, these preprocessing and fine-tuning steps are likely missing, leading to poorer performance.

Instead of using AzureSearchChatDataSource, you can preprocess search results and include them directly in the system prompt.

string searchResults = "Result 1: ...; Result 2: ...;"; string systemPrompt = "You are an AI assistant that helps people find information using the following context:\n" + searchResults + "\nAnswer the user's query using this context."; string userQuery = "What is the main topic discussed in the file?"; var chatOptions = new ChatCompletionsOptions { MaxTokens = 100, Temperature = 0.7 }; chatOptions.Messages.Add(new ChatMessage(ChatRole.System, systemPrompt)); chatOptions.Messages.Add(new ChatMessage(ChatRole.User, userQuery)); Response<ChatCompletions> response = await client.GetChatCompletionsAsync("btGPT4", chatOptions); Console.WriteLine(response.Value.Choices[0].Message.Content);

If the search results are too verbose, summarize them before passing them to the OpenAI model.

string summarizePrompt = "Summarize the following text for use in answering questions:\n" + searchResults; var summarizeOptions = new ChatCompletionsOptions { MaxTokens = 200, Temperature = 0.5 }; summarizeOptions.Messages.Add(new ChatMessage(ChatRole.System, "You are a summarizer.")); summarizeOptions.Messages.Add(new ChatMessage(ChatRole.User, summarizePrompt)); Response<ChatCompletions> summaryResponse = await client.GetChatCompletionsAsync("btGPT4", summarizeOptions); string summarizedContext = summaryResponse.Value.Choices[0].Message.Content;

I have this above scenario with RAG-Based Approach (Manual Retrieval).

Query Azure Cognitive Search for relevant documents. Retrieve and preprocess the search results. Build a structured and optimized prompt then pass the prompt to Azure OpenAI for completion.

Here is my build prompt:

System: You are an AI assistant that provides accurate answers based on the given context. Context: 1. Document 1: [Summary or key text here]. 2. Document 2: [Summary or key text here]. Question: [User query here] Always base your answers on the provided context and explicitly say if the information is not available.

Integrating Cognitive Search with Azure OpenAI:

var searchClient = new SearchClient(new Uri("https://<search-name>.search.windows.net"), "index-name", new AzureKeyCredential("<search-api-key>")); var options = new SearchOptions { Size = 3 }; // Fetch top 3 results options.QueryType = SearchQueryType.Full; options.Select.Add("content"); // Fetch content field var searchResults = searchClient.Search<SearchDocument>("query", options); var context = "Context:\n"; foreach (var result in searchResults.GetResults()) { context += $"- {result.Document["content"]}\n"; } var client = new AzureOpenAIClient(new Uri("https://<openai-resource-name>.openai.azure.com/"), new AzureKeyCredential("<openai-api-key>")); var chatOptions = new ChatCompletionsOptions { Messages = { new ChatMessage(ChatRole.System, "You are an AI assistant that answers based on the provided context."), new ChatMessage(ChatRole.User, context + "Question: " + query) }, MaxTokens = 500 }; var response = client.GetChatCompletions("deployment-name", chatOptions); Console.WriteLine(response.Choices[0].Message.Content);

RAG-based approach is more reliable because it gives you full control over how search results are fetched, processed, and formatted.

2025-08-07 09:37 点击量:12