You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When InvokeStreamingAsync(...) is called on ChatCompletionAgent who has AzureSearchChatDataSource connected to it fails with 400 BadRequest
#pragma warning disable SKEXP0001
#pragma warning disable SKEXP0010
#pragma warning disable SKEXP0110
#pragma warning disable SKEXP0020
#pragma warning disable AOAI001
using Azure.AI.OpenAI.Chat;
using Azure.Search.Documents;
using HeiDi.Sandbox.Utils.Providers;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Agents;
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Connectors.AzureOpenAI;
using System.Text.Json;
var configurationProvider = ConfigurationsProvider.CreateNew();
var aiSearchConfigration = configurationProvider.AiSearchConfiguration;
var openAiConfigration = configurationProvider.OpenAiConfigration;
var datasource = new AzureSearchChatDataSource
{
Endpoint = new Uri(aiSearchConfigration.Endpoint),
Authentication = DataSourceAuthentication.FromApiKey(aiSearchConfigration.ApiKey),
IndexName = "contracts-index",
Filter = SearchFilter.Create($"source_id eq 'generalknowledge'"),
};
var kernel = Kernel.CreateBuilder()
.AddAzureOpenAIChatCompletion(
openAiConfigration.ModelDelpoymentName,
openAiConfigration.Endpoint,
openAiConfigration.ApiKey)
.Build();
var chatHistory = new ChatHistory();
var question = "Could you describe the change request process including all steps?";
Console.WriteLine($"User > {question}");
chatHistory.AddUserMessage(question);
var agent = new ChatCompletionAgent()
{
Description = "You are a frendly assisant for user",
// fail when Instructions has value
Instructions = "Use in your answers the same language than the user has used in the question",
// it will not fail with
/*
Instructions = "",
*/
Name = "open_ai",
Kernel = kernel,
Arguments = new KernelArguments(new AzureOpenAIPromptExecutionSettings()
{
TopP = 0.5,
Temperature = 0.5,
MaxTokens = 1000,
AzureChatDataSource = datasource,
}),
};
var citations = new List<ChatCitation>();
await foreach (var content in agent.InvokeStreamingAsync(chatHistory))
{
var contentReult = content.Content ?? string.Empty;
if (!string.IsNullOrEmpty(contentReult))
Console.WriteLine($"Asistatnt > {contentReult}");
var update = content.InnerContent as OpenAI.Chat.StreamingChatCompletionUpdate;
var messageContext = update?.GetMessageContext();
if (messageContext?.Citations is not null)
{
citations.AddRange(messageContext?.Citations);
}
}
var options = new JsonSerializerOptions { WriteIndented = true };
var json = JsonSerializer.Serialize(citations.Select(x => new Citation(x.Title, x.FilePath, x.Content)).Distinct(), options);
Console.WriteLine($"Tool > Citations: {Environment.NewLine}{json}");
Console.WriteLine("end of the line");
Console.ReadKey();
public record Citation(string Titile, string FileSource, string Content);
Expected behavior
InvokeStreamingAsync(...) method should start stream
Screenshots
If applicable, add screenshots to help explain your problem.
Platform
OS: windows
IDE: Visual Studio
Language: C#
Source: sources are given in setup in to reproduce step
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered:
github-actionsbot
changed the title
Bug: ChatCompletionAgent.InvokeStreamingAsync(...) method when called with data source fails when Instructions not empty
.Net: Bug: ChatCompletionAgent.InvokeStreamingAsync(...) method when called with data source fails when Instructions not empty
Nov 20, 2024
@PanClifton Thanks for creating this issue. Unfortunately, HTTP error message is not included in the exception, so I had to add HTTP logging handler to see what an actual response was. Here is an example of such logging handler, so you can use it for your own purposes in the future:
Based on logging, there is a following error message in response: Validation error at #/messages/0/name: Extra inputs are not permitted.
I removed Name = "open_ai", from ChatCompletionAgent in your code example and it worked as expected. There could be a case that Azure OpenAI Chat Completion with data service doesn't support additional parameters in messages such as agent name.
Describe the bug
When
InvokeStreamingAsync(...)
is called onChatCompletionAgent
who hasAzureSearchChatDataSource
connected to it fails with 400 BadRequestTo Reproduce
Steps to reproduce the behavior:
Setup
csproj
failing code snippet
Expected behavior
InvokeStreamingAsync(...) method should start stream
Screenshots
If applicable, add screenshots to help explain your problem.
Platform
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: