diff --git a/dotnet/src/SemanticKernel.Abstractions/Functions/KernelFunction.cs b/dotnet/src/SemanticKernel.Abstractions/Functions/KernelFunction.cs index fcae054ab679..61c512de9d00 100644 --- a/dotnet/src/SemanticKernel.Abstractions/Functions/KernelFunction.cs +++ b/dotnet/src/SemanticKernel.Abstractions/Functions/KernelFunction.cs @@ -567,68 +567,9 @@ public KernelAIFunction(KernelFunction kernelFunction, Kernel? kernel) // Create the KernelArguments from the supplied arguments. KernelArguments args = []; - - var parsers = new Dictionary>(12) - { - { typeof(bool), s => bool.Parse(s) }, - { typeof(int), s => int.Parse(s) }, - { typeof(uint), s => uint.Parse(s) }, - { typeof(long), s => long.Parse(s) }, - { typeof(ulong), s => ulong.Parse(s) }, - { typeof(float), s => float.Parse(s) }, - { typeof(double), s => double.Parse(s) }, - { typeof(decimal), s => decimal.Parse(s) }, - { typeof(short), s => short.Parse(s) }, - { typeof(ushort), s => ushort.Parse(s) }, - { typeof(byte), s => byte.Parse(s) }, - { typeof(sbyte), s => sbyte.Parse(s) } - }; - foreach (var argument in arguments) { - if (argument.Value is null) - { - args[argument.Key] = null; - continue; - } - - if (argument.Value is not JsonElement or JsonDocument or JsonNode) - { - args[argument.Key] = argument.Value; - continue; - } - - // Resolve the contract used to marshal the value from JSON -- can throw if not supported or not found. - var parameter = this._kernelFunction.Metadata.Parameters.FirstOrDefault(p => p.Name == argument.Key); - if (parameter?.ParameterType is null) - { - args[argument.Key] = argument.Value; - continue; - } - - Type parameterType = parameter.ParameterType; - JsonTypeInfo typeInfo = (this._kernelFunction.JsonSerializerOptions ?? JsonSerializerOptions.Default).GetTypeInfo(parameterType); - - object? argumentValue = null; - if (argument.Value is JsonElement element && element.ValueKind == JsonValueKind.String) - { - if (parsers.TryGetValue(parameterType, out var parser)) - { - args[argument.Key] = parser(element.GetString()!); - continue; - } - } - - argumentValue = argument.Value switch - { - null => null, // Return as-is if null -- if the parameter is a struct this will be handled by MethodInfo.Invoke - JsonElement jsonElement => JsonSerializer.Deserialize(jsonElement, typeInfo), - JsonDocument doc => JsonSerializer.Deserialize(doc, typeInfo), - JsonNode node => JsonSerializer.Deserialize(node, typeInfo), - _ => argument.Value - }; - - args[argument.Key] = argumentValue; + args[argument.Key] = argument.Value; } // Invoke the KernelFunction.