You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.b__0(Context context, Arguments handlebarsArguments)
at HandlebarsDotNet.Helpers.DelegateReturnHelperDescriptor.Invoke(HelperOptions& options, Context& context, Arguments& arguments)
at HandlebarsDotNet.Helpers.DelegateReturnHelperDescriptor.HandlebarsDotNet.Helpers.IHelperDescriptor<HandlebarsDotNet.HelperOptions>.Invoke(HelperOptions& options, Context& context, Arguments& arguments)
at lambda_method348(Closure, EncodedTextWriter&, BindingContext)
at HandlebarsDotNet.HandlebarsEnvironment.<>c__DisplayClass19_0.b__0(TextWriter writer, Object context, Object data)
at HandlebarsDotNet.HandlebarsEnvironment.<>c__DisplayClass20_0.b__0(Object context, Object data)
at Microsoft.SemanticKernel.PromptTemplates.Handlebars.HandlebarsPromptTemplate.RenderAsync(Kernel kernel, KernelArguments arguments, CancellationToken cancellationToken)
at Microsoft.SemanticKernel.Planning.Handlebars.HandlebarsPlan.InvokeCoreAsync(Kernel kernel, KernelArguments arguments, CancellationToken cancellationToken)
at Microsoft.SemanticKernel.Planning.PlannerInstrumentation.InvokePlanAsync[TPlan,TPlanInput,TPlanResult](Func`5 InvokePlanAsync, TPlan plan, Kernel kernel, TPlanInput input, ILogger logger, CancellationToken cancellationToken)
at Backend.Plugins.MathSolverPlugin.SolveAsync(Kernel kernel, String problem) in C:\Users\hanxia\Repos\Hsialab\Next\Backend\Plugins\MathSolverPlugin\MathSolverPlugin.cs:line 43
at Microsoft.SemanticKernel.KernelFunctionFromMethod.<>c.<b__12_4>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.SemanticKernel.KernelFunction.InvokeAsync(Kernel kernel, KernelArguments arguments, CancellationToken cancellationToken)
To Reproduce
Steps to reproduce the behavior:
kernelWithMath.Plugins.AddFromType();
var planner = new HandlebarsPlanner(new HandlebarsPlannerOptions() { AllowLoops = true });
// Create a plan
var plan = await planner.CreatePlanAsync(kernelWithMath, problem);
// Execute the plan
var result = (await plan.InvokeAsync(kernelWithMath)).Trim();
Input a quadratic equation with one unknown to resolve. And the equation has no solution.
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.
The text was updated successfully, but these errors were encountered:
github-actionsbot
changed the title
KernelFunctionHelpers.ParseResult report exception when the result is NaN or Infinity
.Net: KernelFunctionHelpers.ParseResult report exception when the result is NaN or Infinity
Feb 1, 2024
github-actionsbot
changed the title
.Net: KernelFunctionHelpers.ParseResult report exception when the result is NaN or Infinity
Python: KernelFunctionHelpers.ParseResult report exception when the result is NaN or Infinity
Feb 1, 2024
moonbox3
changed the title
Python: KernelFunctionHelpers.ParseResult report exception when the result is NaN or Infinity
.Net: KernelFunctionHelpers.ParseResult report exception when the result is NaN or Infinity
Feb 5, 2024
… FP literals (#5183)
### Motivation and Context
<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
1. Why is this change required?
2. What problem does it solve?
3. What scenario does it contribute to?
4. If it fixes an open issue, please link to the issue here.
-->
Adding #each block details + jsonSerializer fix to handle named FP
literals
Resolves#4838
### Contribution Checklist
<!-- Before submitting this PR, please make sure: -->
- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
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.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)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.WriteString[TValue](TValue& value, JsonTypeInfo
1 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.b__0(Context context, Arguments handlebarsArguments)
at HandlebarsDotNet.Helpers.DelegateReturnHelperDescriptor.Invoke(HelperOptions& options, Context& context, Arguments& arguments)
at HandlebarsDotNet.Helpers.DelegateReturnHelperDescriptor.HandlebarsDotNet.Helpers.IHelperDescriptor<HandlebarsDotNet.HelperOptions>.Invoke(HelperOptions& options, Context& context, Arguments& arguments)
at lambda_method348(Closure, EncodedTextWriter&, BindingContext)
at HandlebarsDotNet.HandlebarsEnvironment.<>c__DisplayClass19_0.b__0(TextWriter writer, Object context, Object data)
at HandlebarsDotNet.HandlebarsEnvironment.<>c__DisplayClass20_0.b__0(Object context, Object data)
at Microsoft.SemanticKernel.PromptTemplates.Handlebars.HandlebarsPromptTemplate.RenderAsync(Kernel kernel, KernelArguments arguments, CancellationToken cancellationToken)
at Microsoft.SemanticKernel.Planning.Handlebars.HandlebarsPlan.InvokeCoreAsync(Kernel kernel, KernelArguments arguments, CancellationToken cancellationToken)
at Microsoft.SemanticKernel.Planning.PlannerInstrumentation.InvokePlanAsync[TPlan,TPlanInput,TPlanResult](Func`5 InvokePlanAsync, TPlan plan, Kernel kernel, TPlanInput input, ILogger logger, CancellationToken cancellationToken)
at Backend.Plugins.MathSolverPlugin.SolveAsync(Kernel kernel, String problem) in C:\Users\hanxia\Repos\Hsialab\Next\Backend\Plugins\MathSolverPlugin\MathSolverPlugin.cs:line 43
at Microsoft.SemanticKernel.KernelFunctionFromMethod.<>c.<b__12_4>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.SemanticKernel.KernelFunction.InvokeAsync(Kernel kernel, KernelArguments arguments, CancellationToken cancellationToken)
To Reproduce
Steps to reproduce the behavior:
kernelWithMath.Plugins.AddFromType();
var planner = new HandlebarsPlanner(new HandlebarsPlannerOptions() { AllowLoops = true });
// Create a plan
var plan = await planner.CreatePlanAsync(kernelWithMath, problem);
// Execute the plan
var result = (await plan.InvokeAsync(kernelWithMath)).Trim();
Input a quadratic equation with one unknown to resolve. And the equation has no solution.
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
Additional context
Use MathPlugin in DocumentationExamples. But add a function Negate otherwise the equation can not be solved.
The text was updated successfully, but these errors were encountered: