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

Bug: Ollama connector fails when calling plugin functions that have parameters with Guid type #9711

Closed
nitrovent opened this issue Nov 14, 2024 · 1 comment · Fixed by #9784
Assignees
Labels
ai connector Anything related to AI connectors bug Something isn't working .NET Issue or Pull requests regarding .NET code

Comments

@nitrovent
Copy link

nitrovent commented Nov 14, 2024

Describe the bug
Function call fails when trying to call function that has guid parameter:

fail: Microsoft.SemanticKernel.KernelFunction[0]
      Function TodoPlugin-SetCompleted failed. Error: No converter found to convert from System.Guid to System.Text.Json.JsonElement. (Parameter 'id')
      Actual value was 9416a630-d9ca-45d0-bf02-3f8d0d3e17bb.
      System.ArgumentOutOfRangeException: No converter found to convert from System.Guid to System.Text.Json.JsonElement. (Parameter 'id')
      Actual value was 9416a630-d9ca-45d0-bf02-3f8d0d3e17bb.
         at Microsoft.SemanticKernel.KernelFunctionFromMethod.<>c__DisplayClass22_0.<GetParameterMarshalerDelegate>g__Process|10(Object value, <>c__DisplayClass22_1&)
         at Microsoft.SemanticKernel.KernelFunctionFromMethod.<>c__DisplayClass22_0.<GetParameterMarshalerDelegate>g__parameterFunc|9(KernelFunction _, Kernel kernel, KernelArguments arguments, CancellationToken __)
         at Microsoft.SemanticKernel.KernelFunctionFromMethod.<>c__DisplayClass20_0.<GetMethodDetails>g__Function|0(Kernel kernel, KernelFunction function, KernelArguments arguments, CancellationToken cancellationToken)
         at Microsoft.SemanticKernel.KernelFunctionFromMethod.InvokeCoreAsync(Kernel kernel, KernelArguments arguments, CancellationToken cancellationToken)
         at Microsoft.SemanticKernel.KernelFunction.<>c__DisplayClass27_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 Microsoft.SemanticKernel.Kernel.OnFunctionInvocationAsync(KernelFunction function, KernelArguments arguments, FunctionResult functionResult, Boolean isStreaming, Func`2 functionCallback, CancellationToken cancellationToken)
         at Microsoft.SemanticKernel.KernelFunction.InvokeAsync(Kernel kernel, KernelArguments arguments, CancellationToken cancellationToken)

To Reproduce
Steps to reproduce the behavior:

  1. Add plugin with function with guid parameter, in my case:
[KernelFunction, Description("Set the completed state of a todo")]
public void SetCompleted(
    [Description("Determines the id of the todo to toggle")] Guid id, 
    [Description("Determines whether to to complete or to resume the todo")] bool complete = true) 
{ 
//...
}
  1. Give instructions that will call the function

Expected behavior
Function calls work with functions with guid parameters

Platform

  • Language: C#
  • Source: Nuget dotnet-1.29.0

Additional context
Works well with the Azure connector.

@nitrovent nitrovent added the bug Something isn't working label Nov 14, 2024
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code triage labels Nov 14, 2024
@github-actions github-actions bot changed the title Bug: Ollama connector fails when calling plugin functions that have boolean parameters .Net: Bug: Ollama connector fails when calling plugin functions that have boolean parameters Nov 14, 2024
@nitrovent nitrovent changed the title .Net: Bug: Ollama connector fails when calling plugin functions that have boolean parameters Bug: Ollama connector fails when calling plugin functions that have parameters with Guid type Nov 14, 2024
@nitrovent
Copy link
Author

Edit because I thought I it was with a boolean parameter. I am sure I saw that error for boolean, too when testing.

@markwallace-microsoft markwallace-microsoft added ai connector Anything related to AI connectors and removed triage labels Nov 18, 2024
github-merge-queue bot pushed a commit that referenced this issue Nov 22, 2024
… (SLM Function Calling) (#9784)

### Motivation and Context

In the original logic the conversion was giving priority for existence
of converters when the parameter value was a
JsonElement/JsonDocument/JsonNode, this change checks if the argument is
one of those types first and use the proper JSON conversion.

This change also bring some resiliency when the `JsonElement` provided
is a `string` for primitive types like `boolean` and C# numeric types.

This change improves function calling experience when using local models
that send JSON string argument values ("1" or "true") instead of the
expected JSON type (1, true) for calling functions.
i.e: `Llama 3.1, Llama 3.2`

Added Unit Tests covering the added JsonElement arguments support.

- Fixes #9711 
- Extra (Remove of Warning for ONNX connectors SYSLIB1222)

---------

Co-authored-by: Dmytro Struk <[email protected]>
@github-project-automation github-project-automation bot moved this from Sprint: In Progress to Sprint: Done in Semantic Kernel Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ai connector Anything related to AI connectors bug Something isn't working .NET Issue or Pull requests regarding .NET code
Projects
Status: Sprint: Done
3 participants