Description
Describe the bug
If I were to invoke the method ChatHistory.AddSystemMessage along with Microsoft.SemanticKernel.Connectors.Google
chatCompletionService.GetChatMessageContentAsync throws an exception.
To Reproduce
This is my sample code:
#pragma warning disable SKEXP0070
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.SemanticKernel.Connectors.Google;
IKernelBuilder kernelBuilder = Kernel.CreateBuilder();
kernelBuilder.AddGoogleAIGeminiChatCompletion(
modelId: "gemini-2.0-flash",
apiKey: "API_KEY",
httpClient: new HttpClient() // Optional; for customizing HTTP client
);
Kernel kernel = kernelBuilder.Build();
var chatCompletionService = kernel.GetRequiredService();
ChatHistory history = [];
//history.AddSystemMessage("You are my tour guide at Yosemite National Park!");
history.AddUserMessage("Hello, how are you?");
string[] questions = new[] {
"What is the best time to visit Yosemite?",
"What are the main attractions in Yosemite?",
"How do I get to Yosemite from San Francisco?",
"What should I pack for a trip to Yosemite?",
"Are there any guided tours available in Yosemite?"
};
foreach (string question in questions)
{
history.AddUserMessage(question);
ChatMessageContent responseContent = await chatCompletionService.GetChatMessageContentAsync(history);
if (responseContent != null && responseContent.Content != null)
{
history.AddAssistantMessage(responseContent.Content);
Console.WriteLine($"Q: {question}\nA: {responseContent.Content}\n");
}
else
{
Console.WriteLine($"Q: {question}\nA: No response received.\n");
}
}
If I were to uncomment the call to AddSystemMessage the application throws an exception.
Expected behavior
AddSystemMessage shouldn't affect this console application.
Screenshots
If applicable, add screenshots to help explain your problem.
Platform
- Language: C#
- Source: Microsoft.SemanticKernel.Connectors.Google -Version 1.56.0-alpha
- AI model: gemini-2.0-flash
- IDE: Visual Studio
- OS: Windows 11
Additional context
n/a
Metadata
Metadata
Assignees
Type
Projects
Status