microsoft / semantic-kernel

Integrate cutting-edge LLM technology quickly and easily into your apps
https://aka.ms/semantic-kernel
MIT License
22.07k stars 3.29k forks source link

.Net: Add JsonElement String to Primitive Implicit Conversion Support (SLM Function Calling) #9784

Closed RogerBarreto closed 2 days ago

RogerBarreto commented 3 days ago

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.