147 references to AIJsonUtilities
Microsoft.Extensions.AI (13)
Microsoft.Extensions.AI.Abstractions (29)
Functions\AIFunctionFactory.cs (17)
90/// or else using <see cref="AIJsonUtilities.DefaultOptions"/>. If the argument is anything else, it is round-tripped through JSON, serializing the object as JSON
101/// <see cref="AIFunctionFactoryOptions.SerializerOptions"/> if provided, or else using <see cref="AIJsonUtilities.DefaultOptions"/>.
169/// <see cref="AIJsonUtilities.DefaultOptions"/>. If the argument is anything else, it is round-tripped through JSON, serializing the object as JSON
180/// or else using <see cref="AIJsonUtilities.DefaultOptions"/>. However, return values whose declared type is <see cref="AIContent"/>, a
260/// or else using <see cref="AIJsonUtilities.DefaultOptions"/>. If the argument is anything else, it is round-tripped through JSON, serializing the object as JSON
271/// <see cref="AIFunctionFactoryOptions.SerializerOptions"/> if provided, or else using <see cref="AIJsonUtilities.DefaultOptions"/>.
346/// <see cref="AIJsonUtilities.DefaultOptions"/>. If the argument is anything else, it is round-tripped through JSON, serializing the object as JSON
357/// or else using <see cref="AIJsonUtilities.DefaultOptions"/>. However, return values whose declared type is <see cref="AIContent"/>, a
450/// or else using <see cref="AIJsonUtilities.DefaultOptions"/>. If the argument is anything else, it is round-tripped through JSON, serializing the object as JSON
461/// <see cref="AIFunctionFactoryOptions.SerializerOptions"/> if provided, or else using <see cref="AIJsonUtilities.DefaultOptions"/>.
655JsonSerializerOptions serializerOptions = options.SerializerOptions ?? AIJsonUtilities.DefaultOptions;
735ReturnJsonSchema = returnType is null || key.ExcludeResultSchema ? null : AIJsonUtilities.CreateJsonSchema(
741JsonSchema = AIJsonUtilities.CreateFunctionJsonSchema(
847bool hasDefault = AIJsonUtilities.TryGetEffectiveDefaultValue(parameter, out _);
863bool hasDefaultValue = AIJsonUtilities.TryGetEffectiveDefaultValue(parameter, out object? effectiveDefaultValue);
1128options ??= AIJsonUtilities.DefaultOptions;
1130if (options == AIJsonUtilities.DefaultOptions && !options.TryGetTypeInfo(type, out _))
Microsoft.Extensions.AI.Abstractions.Tests (69)
Utilities\AIJsonUtilitiesTests.cs (52)
30var options = AIJsonUtilities.DefaultOptions;
34Assert.Same(options, AIJsonUtilities.DefaultOptions);
56var options = AIJsonUtilities.DefaultOptions;
66var options = AIJsonUtilities.DefaultOptions;
70Assert.Equal(JsonSerializer.IsReflectionEnabledByDefault, AIJsonUtilities.DefaultOptions.TryGetTypeInfo(anonType, out _));
168JsonElement actual = AIJsonUtilities.CreateJsonSchema(typeof(MyPoco), serializerOptions: JsonContext.Default.Options);
183JsonElement actual = AIJsonUtilities.CreateJsonSchema(typeof(object[]), serializerOptions: JsonContext.Default.Options);
226JsonElement actual = AIJsonUtilities.CreateJsonSchema(
276JsonElement actual = AIJsonUtilities.CreateJsonSchema(typeof(MyPoco), serializerOptions: JsonContext.Default.Options, inferenceOptions: inferenceOptions);
284JsonSerializerOptions options = new(AIJsonUtilities.DefaultOptions);
289JsonElement resolvedSchema = AIJsonUtilities.CreateFunctionJsonSchema(func.UnderlyingMethod, title: string.Empty);
352JsonElement resolvedSchema = AIJsonUtilities.CreateFunctionJsonSchema(func.UnderlyingMethod, title: string.Empty, description: string.Empty, inferenceOptions: inferenceOptions);
359JsonSerializerOptions options = new(AIJsonUtilities.DefaultOptions) { NumberHandling = JsonNumberHandling.AllowReadingFromString };
409JsonSerializerOptions options = new(AIJsonUtilities.DefaultOptions) { NumberHandling = JsonNumberHandling.AllowReadingFromString };
437JsonElement schema = AIJsonUtilities.CreateFunctionJsonSchema(method);
456JsonElement schema = AIJsonUtilities.CreateFunctionJsonSchema(method, title: "override_title");
466JsonElement schema = AIJsonUtilities.CreateJsonSchema(typeof(object));
485JsonElement schema = AIJsonUtilities.CreateJsonSchema(testData.Type, serializerOptions: options, inferenceOptions: createOptions);
510JsonElement schema = AIJsonUtilities.CreateJsonSchema(typeof(AIContent), serializerOptions: options);
514Assert.Same(options.TypeInfoResolver, AIJsonUtilities.DefaultOptions.TypeInfoResolver);
527JsonElement schema = AIJsonUtilities.CreateJsonSchema(typeof(MyEnumValue?), serializerOptions: JsonContext.Default.Options);
762AIJsonUtilities.CreateJsonSchema(typeof(CreateJsonSchema_IncorporatesTypesAndAnnotations_Type), serializerOptions: JsonContext.Default.Options));
921AIJsonUtilities.CreateJsonSchema(typeof(CreateJsonSchema_IncorporatesTypesAndAnnotations_Type), serializerOptions: JsonContext.Default.Options));
1028JsonElement actualSchema = AIJsonUtilities.CreateJsonSchema(typeof(ClassWithNullableMaxLengthProperty), serializerOptions: JsonContext.Default.Options);
1044TypeInfoResolver = JsonTypeInfoResolver.Combine(AIJsonUtilities.DefaultOptions.TypeInfoResolver, JsonContext.Default),
1061Assert.Throws<InvalidOperationException>(() => AIJsonUtilities.DefaultOptions.AddAIContentType<DerivedAIContent>("derivativeContent"));
1108TypeInfoResolver = AIJsonUtilities.DefaultOptions.TypeInfoResolver
1111foreach (JsonSerializerOptions? options in new[] { AIJsonUtilities.DefaultOptions, null, customOptions })
1113string key1 = AIJsonUtilities.HashDataToString(["a", 'b', 42], options);
1114string key2 = AIJsonUtilities.HashDataToString(["a", 'b', 42], options);
1115string key3 = AIJsonUtilities.HashDataToString([TimeSpan.FromSeconds(1), null, 1.23], options);
1116string key4 = AIJsonUtilities.HashDataToString([TimeSpan.FromSeconds(1), null, 1.23], options);
1117string key5 = AIJsonUtilities.HashDataToString([new Dictionary<string, object> { ["key1"] = 1, ["key2"] = 2 }], options);
1118string key6 = AIJsonUtilities.HashDataToString([new Dictionary<string, object> { ["key2"] = 2, ["key1"] = 1 }], options);
1131JsonSerializerOptions indentOptions = new(AIJsonUtilities.DefaultOptions) { WriteIndented = true };
1132JsonSerializerOptions noIndentOptions = new(AIJsonUtilities.DefaultOptions) { WriteIndented = false };
1135string key1 = AIJsonUtilities.HashDataToString([dict], indentOptions);
1136string key2 = AIJsonUtilities.HashDataToString([dict], noIndentOptions);
1147JsonElement schema = AIJsonUtilities.CreateFunctionJsonSchema(method.Method, inferenceOptions: new()
1196JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, options);
1230JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, options);
1265JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, options);
1302JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, options);
1329JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, options);
1348JsonElement schema = AIJsonUtilities.CreateJsonSchema(testData.Type, serializerOptions: options, inferenceOptions: createOptions);
1366JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, transformOptions);
1393AIJsonUtilities.TransformSchema(transformedSchema, transformOptions);
1401Assert.Throws<ArgumentNullException>(() => AIJsonUtilities.TransformSchema(schema, transformOptions: null!));
1402Assert.Throws<ArgumentException>(() => AIJsonUtilities.TransformSchema(schema, transformOptions: new()));
1415Assert.Throws<ArgumentException>(() => AIJsonUtilities.TransformSchema(schema, transformOptions));
1438JsonSerializer.SerializeToNode(element1, AIJsonUtilities.DefaultOptions),
1439JsonSerializer.SerializeToNode(element2, AIJsonUtilities.DefaultOptions));
Microsoft.Extensions.AI.AzureAIInference (7)
Microsoft.Extensions.AI.AzureAIInference.Tests (3)
Microsoft.Extensions.AI.Evaluation.Quality (2)
Microsoft.Extensions.AI.Evaluation.Reporting (1)
Microsoft.Extensions.AI.Evaluation.Reporting.Azure (1)
Microsoft.Extensions.AI.Integration.Tests (1)
Microsoft.Extensions.AI.OpenAI (8)
Microsoft.Extensions.AI.OpenAI.Tests (3)
Microsoft.Extensions.AI.Tests (10)