Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.Net: The Gemini connector throws exceptions in parallel tool calls #6282

Open
TaoChenOSU opened this issue May 16, 2024 · 0 comments
Open
Assignees
Labels
bug Something isn't working .NET Issue or Pull requests regarding .NET code

Comments

@TaoChenOSU
Copy link
Contributor

TaoChenOSU commented May 16, 2024

Describe the bug
This is related to #6281.

Using the Gemini connector results in exceptions. It still invokes the function multiple times. However, instead of returning a poem at the end, it throws an exception:

Unhandled exception. System.NotSupportedException: Runtime type 'Microsoft.SemanticKernel.Connectors.Google.GeminiChatMessageContent' is not supported by polymorphic type 'Microsoft.SemanticKernel.KernelContent'. Path: $.
 ---> System.NotSupportedException: Runtime type 'Microsoft.SemanticKernel.Connectors.Google.GeminiChatMessageContent' is not supported by polymorphic type 'Microsoft.SemanticKernel.KernelContent'.
   at System.Text.Json.ThrowHelper.ThrowNotSupportedException_RuntimeTypeNotSupported(Type baseType, Type runtimeType)
   at System.Text.Json.Serialization.Metadata.PolymorphicTypeResolver.TryGetDerivedJsonTypeInfo(Type runtimeType, JsonTypeInfo& jsonTypeInfo, Object& typeDiscriminator)
   at System.Text.Json.Serialization.JsonConverter.ResolvePolymorphicConverter(Object value, JsonTypeInfo jsonTypeInfo, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
   --- End of inner exception stack trace ---
   at System.Text.Json.ThrowHelper.ThrowNotSupportedException(WriteStack& state, NotSupportedException ex)
   at System.Text.Json.Serialization.JsonConverter`1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.Serialize(Utf8JsonWriter writer, T& rootValue, Object rootValueBoxed)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.SerializeAsObject(Utf8JsonWriter writer, Object rootValue)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.Serialize(Utf8JsonWriter writer, T& rootValue, Object rootValueBoxed)
   at System.Text.Json.JsonSerializer.WriteNode[TValue](TValue& value, JsonTypeInfo`1 jsonTypeInfo)
   at System.Text.Json.JsonSerializer.SerializeToNode[TValue](TValue value, JsonSerializerOptions options)
   at Microsoft.SemanticKernel.Connectors.Google.Core.GeminiPart.FunctionResponsePart.FunctionResponseEntity..ctor(Object response)
   at Microsoft.SemanticKernel.Connectors.Google.Core.GeminiRequest.CreateGeminiParts(ChatMessageContent content)
   at Microsoft.SemanticKernel.Connectors.Google.Core.GeminiRequest.CreateGeminiContentFromChatMessage(ChatMessageContent message)
   at Microsoft.SemanticKernel.Connectors.Google.Core.GeminiRequest.AddChatMessage(ChatMessageContent message)
   at Microsoft.SemanticKernel.Connectors.Google.Core.GeminiChatCompletionClient.AddToolResponseMessage(ChatHistory chat, GeminiRequest request, GeminiFunctionToolCall tool, FunctionResult functionResponse, String errorMessage)
   at Microsoft.SemanticKernel.Connectors.Google.Core.GeminiChatCompletionClient.ProcessSingleToolCallAsync(ChatCompletionState state, GeminiFunctionToolCall toolCall, CancellationToken cancellationToken)
   at Microsoft.SemanticKernel.Connectors.Google.Core.GeminiChatCompletionClient.ProcessFunctionsAsync(ChatCompletionState state, CancellationToken cancellationToken)
   at Microsoft.SemanticKernel.Connectors.Google.Core.GeminiChatCompletionClient.GenerateChatMessageAsync(ChatHistory chatHistory, PromptExecutionSettings executionSettings, Kernel kernel, CancellationToken cancellationToken)
   at Microsoft.SemanticKernel.ChatCompletion.ChatCompletionServiceExtensions.GetChatMessageContentAsync(IChatCompletionService chatCompletionService, String prompt, PromptExecutionSettings executionSettings, Kernel kernel, CancellationToken cancellationToken)
   at Microsoft.SemanticKernel.KernelFunctionFromPrompt.InvokeCoreAsync(Kernel kernel, KernelArguments arguments, CancellationToken cancellationToken)
   at Microsoft.SemanticKernel.KernelFunction.<>c__DisplayClass21_0.<<InvokeAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.SemanticKernel.Kernel.InvokeFilterOrFunctionAsync(NonNullCollection`1 functionFilters, Func`2 functionCallback, FunctionInvocationContext context, Int32 index)
   at Program.FirstFunctionFilter.OnFunctionInvocationAsync(FunctionInvocationContext context, Func`2 next) in C:\Users\taochen\Projects\ScratchPad\Program.cs:line 67
   at Microsoft.SemanticKernel.Kernel.InvokeFilterOrFunctionAsync(NonNullCollection`1 functionFilters, Func`2 functionCallback, FunctionInvocationContext context, Int32 index)
   at Microsoft.SemanticKernel.Kernel.OnFunctionInvocationAsync(KernelFunction function, KernelArguments arguments, FunctionResult functionResult, Func`2 functionCallback)
   at Microsoft.SemanticKernel.KernelFunction.InvokeAsync(Kernel kernel, KernelArguments arguments, CancellationToken cancellationToken)
   at Microsoft.SemanticKernel.Kernel.InvokeAsync[TResult](String pluginName, String functionName, KernelArguments arguments, CancellationToken cancellationToken)
   at Program.Main() in C:\Users\taochen\Projects\ScratchPad\Program.cs:line 29
   at Program.<Main>()

To Reproduce
Steps to reproduce the behavior:

  1. Follow the repro in: .Net: Invoking kernel function directly with auto invoke enabled results in multiple nested calls to the function #6281
  2. Use the Gemini connector instead of the OpenAI connector.
  3. Use a Gemini setting: GeminiPromptExecutionSettings settings = new() { ToolCallBehavior = GeminiToolCallBehavior.AutoInvokeKernelFunctions };

Expected behavior
Return a poem.

There won't be any exception and the code correctly returns a poem with auto invoked disabled. This is because the function will only be invoked once.

Platform

  • OS: Windows
  • IDE: VS Code
  • Language: C#
  • Source: main branch of repository

Additional context
Tested with gemini-1.0-pro

@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code triage labels May 16, 2024
@github-actions github-actions bot changed the title The Gemini connector throws exceptions in parallel tool calls .Net: The Gemini connector throws exceptions in parallel tool calls May 16, 2024
@markwallace-microsoft markwallace-microsoft added bug Something isn't working and removed triage labels May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working .NET Issue or Pull requests regarding .NET code
Projects
Status: Bugs
Development

No branches or pull requests

3 participants