.Net: KernelFunctionHelpers.ParseResult report exception when the result is NaN or Infinity
Describe the bug
KernelFunctionHelpers.ParseResult report exception when the result is NaN or Infinity
An unhandled exception has occurred while executing the request.
System.ArgumentException: .NET number values such as positive and negative infinity cannot be written as valid JSON. To make it work when using 'JsonSerializer', consider specifying 'JsonNumberHandling.AllowNamedFloatingPointLiterals' (see https://docs.microsoft.com/dotnet/api/system.text.json.serialization.jsonnumberhandling).
at System.Text.Json.ThrowHelper.ThrowArgumentException_ValueNotSupported()
at System.Text.Json.Utf8JsonWriter.WriteNumberValue(Double value)
at System.Text.Json.Serialization.JsonConverter1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.JsonConverter1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo1.Serialize(Utf8JsonWriter writer, T& rootValue, Object rootValueBoxed)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo1.SerializeAsObject(Utf8JsonWriter writer, Object rootValue)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo1.Serialize(Utf8JsonWriter writer, T& rootValue, Object rootValueBoxed)
at System.Text.Json.JsonSerializer.WriteString[TValue](TValue& value, JsonTypeInfo1 jsonTypeInfo)
at System.Text.Json.JsonSerializer.Serialize[TValue](TValue value, JsonSerializerOptions options)
at Microsoft.SemanticKernel.PromptTemplates.Handlebars.Helpers.KernelFunctionHelpers.ParseResult(FunctionResult result)
at Microsoft.SemanticKernel.PromptTemplates.Handlebars.Helpers.KernelFunctionHelpers.InvokeKernelFunction(Kernel kernel, KernelFunction function, KernelArguments executionContext, CancellationToken cancellationToken)
at Microsoft.SemanticKernel.PromptTemplates.Handlebars.Helpers.KernelFunctionHelpers.<>c__DisplayClass1_0.
To Reproduce
Steps to reproduce the behavior:
kernelWithMath.Plugins.AddFromType
Expected behavior add allowNamedFloatingPointLiterals options when serializing the return value. Or provide option to set the json serialize/deserialize settings. In my case. output that the equation has no solution without any exception.
Platform
- OS: [e.g. Windows, Mac] Windows
- IDE: [e.g. Visual Studio, VS Code] Visual Sutudio
- Language: [e.g. C#, Python] C#
- Source: [e.g. NuGet package version 0.1.0, pip package version 0.1.0, main branch of repository] SK 1.3
Additional context Use MathPlugin in DocumentationExamples. But add a function Negate otherwise the equation can not be solved.