118 references to AIJsonUtilities
Microsoft.Extensions.AI (12)
ChatCompletion\ChatClientStructuredOutputExtensions.cs (3)
54GetResponseAsync<T>(chatClient, messages, AIJsonUtilities.DefaultOptions, options, useJsonSchemaResponseFormat, cancellationToken); 164var schemaElement = AIJsonUtilities.CreateJsonSchema( 190}, AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(JsonObject)));
ChatCompletion\DistributedCachingChatClient.cs (2)
50private JsonSerializerOptions _jsonSerializerOptions = AIJsonUtilities.DefaultOptions; 156return AIJsonUtilities.HashDataToString(arr.AsSpan(0, length), _jsonSerializerOptions);
ChatCompletion\LoggingChatClient.cs (1)
43_jsonSerializerOptions = AIJsonUtilities.DefaultOptions;
ChatCompletion\OpenTelemetryChatClient.cs (1)
90_jsonSerializerOptions = AIJsonUtilities.DefaultOptions;
Embeddings\DistributedCachingEmbeddingGenerator.cs (2)
52_jsonSerializerOptions = AIJsonUtilities.DefaultOptions; 125return AIJsonUtilities.HashDataToString(arr.AsSpan(0, length), _jsonSerializerOptions);
Embeddings\LoggingEmbeddingGenerator.cs (1)
45_jsonSerializerOptions = AIJsonUtilities.DefaultOptions;
LoggingHelpers.cs (1)
19AIJsonUtilities.DefaultOptions.TryGetTypeInfo(typeof(T), out typeInfo))
SpeechToText\LoggingSpeechToTextClient.cs (1)
46_jsonSerializerOptions = AIJsonUtilities.DefaultOptions;
Microsoft.Extensions.AI.Abstractions (23)
Functions\AIFunction.cs (2)
39public virtual JsonElement JsonSchema => AIJsonUtilities.DefaultJsonSchema; 57public virtual JsonSerializerOptions JsonSerializerOptions => AIJsonUtilities.DefaultOptions;
Functions\AIFunctionFactory.cs (13)
94/// or else using <see cref="AIJsonUtilities.DefaultOptions"/>. If the argument is anything else, it is round-tripped through JSON, serializing the object as JSON 105/// <see cref="AIFunctionFactoryOptions.SerializerOptions"/> if provided, or else using <see cref="AIJsonUtilities.DefaultOptions"/>. 168/// <see cref="AIJsonUtilities.DefaultOptions"/>. If the argument is anything else, it is round-tripped through JSON, serializing the object as JSON 179/// or else using <see cref="AIJsonUtilities.DefaultOptions"/>. 257/// or else using <see cref="AIJsonUtilities.DefaultOptions"/>. If the argument is anything else, it is round-tripped through JSON, serializing the object as JSON 268/// <see cref="AIFunctionFactoryOptions.SerializerOptions"/> if provided, or else using <see cref="AIJsonUtilities.DefaultOptions"/>. 341/// <see cref="AIJsonUtilities.DefaultOptions"/>. If the argument is anything else, it is round-tripped through JSON, serializing the object as JSON 352/// or else using <see cref="AIJsonUtilities.DefaultOptions"/>. 443/// or else using <see cref="AIJsonUtilities.DefaultOptions"/>. If the argument is anything else, it is round-tripped through JSON, serializing the object as JSON 454/// <see cref="AIFunctionFactoryOptions.SerializerOptions"/> if provided, or else using <see cref="AIJsonUtilities.DefaultOptions"/>. 613JsonSerializerOptions serializerOptions = options.SerializerOptions ?? AIJsonUtilities.DefaultOptions; 693ReturnJsonSchema = returnType is null || key.ExcludeResultSchema ? null : AIJsonUtilities.CreateJsonSchema( 699JsonSchema = AIJsonUtilities.CreateFunctionJsonSchema(
Functions\AIFunctionFactoryOptions.cs (1)
28/// If no value has been specified, the <see cref="AIJsonUtilities.DefaultOptions"/> instance will be used.
Utilities\AIJsonSchemaCreateContext.cs (1)
19/// callback by the <see cref="AIJsonUtilities.CreateJsonSchema"/> method and cannot be instantiated directly.
Utilities\AIJsonSchemaCreateOptions.cs (2)
14/// Provides options for configuring the behavior of <see cref="AIJsonUtilities"/> JSON schema creation functionality. 30/// <see cref="AIJsonUtilities.CreateFunctionJsonSchema"/> in order to determine whether it should
Utilities\AIJsonSchemaTransformCache.cs (2)
46_functionSchemaCreateValueCallback = function => AIJsonUtilities.TransformSchema(function.JsonSchema, TransformOptions); 47_responseFormatCreateValueCallback = responseFormat => AIJsonUtilities.TransformSchema(responseFormat.Schema!.Value, TransformOptions);
Utilities\AIJsonSchemaTransformContext.cs (1)
15/// callback by the <see cref="AIJsonUtilities.CreateJsonSchema"/> method and cannot be instantiated directly.
Utilities\AIJsonSchemaTransformOptions.cs (1)
12/// Provides options for configuring the behavior of <see cref="AIJsonUtilities"/> JSON schema transformation functionality.
Microsoft.Extensions.AI.Abstractions.Tests (55)
AssertExtensions.cs (3)
62JsonSerializer.SerializeToNode(expectedJson, AIJsonUtilities.DefaultOptions), 63JsonSerializer.SerializeToNode(actualJson, AIJsonUtilities.DefaultOptions))) 75options ??= AIJsonUtilities.DefaultOptions;
ChatCompletion\ChatResponseFormatTests.cs (1)
74ChatResponseFormat.ForJsonSchema(JsonSerializer.Deserialize<JsonElement>("[1,2,3]", AIJsonUtilities.DefaultOptions), "name", "description"),
Contents\AIContentTests.cs (2)
47string json = JsonSerializer.Serialize(original, AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(AIContent))); 50AIContent? deserialized = (AIContent?)JsonSerializer.Deserialize(json, AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(AIContent)));
Contents\ErrorContentTests.cs (1)
54JsonSerializerOptions options = new(AIJsonUtilities.DefaultOptions) { PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
Contents\FunctionCallContentTests..cs (1)
265argumentParser: static json => JsonSerializer.Deserialize<Dictionary<string, object?>>(json, AIJsonUtilities.DefaultOptions));
Utilities\AIJsonUtilitiesTests.cs (47)
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); 211JsonElement actual = AIJsonUtilities.CreateJsonSchema( 261JsonElement actual = AIJsonUtilities.CreateJsonSchema(typeof(MyPoco), serializerOptions: JsonContext.Default.Options, inferenceOptions: inferenceOptions); 269JsonSerializerOptions options = new(AIJsonUtilities.DefaultOptions); 274JsonElement resolvedSchema = AIJsonUtilities.CreateFunctionJsonSchema(func.UnderlyingMethod, title: string.Empty); 337JsonElement resolvedSchema = AIJsonUtilities.CreateFunctionJsonSchema(func.UnderlyingMethod, title: string.Empty, description: string.Empty, inferenceOptions: inferenceOptions); 344JsonSerializerOptions options = new(AIJsonUtilities.DefaultOptions) { NumberHandling = JsonNumberHandling.AllowReadingFromString }; 394JsonElement schema = AIJsonUtilities.CreateJsonSchema(typeof(object)); 413JsonElement schema = AIJsonUtilities.CreateJsonSchema(testData.Type, serializerOptions: options, inferenceOptions: createOptions); 438JsonElement schema = AIJsonUtilities.CreateJsonSchema(typeof(AIContent), serializerOptions: options); 442Assert.Same(options.TypeInfoResolver, AIJsonUtilities.DefaultOptions.TypeInfoResolver); 455JsonElement schema = AIJsonUtilities.CreateJsonSchema(typeof(MyEnumValue?), serializerOptions: JsonContext.Default.Options); 690AIJsonUtilities.CreateJsonSchema(typeof(CreateJsonSchema_IncorporatesTypesAndAnnotations_Type), serializerOptions: JsonContext.Default.Options)); 849AIJsonUtilities.CreateJsonSchema(typeof(CreateJsonSchema_IncorporatesTypesAndAnnotations_Type), serializerOptions: JsonContext.Default.Options)); 945TypeInfoResolver = JsonTypeInfoResolver.Combine(AIJsonUtilities.DefaultOptions.TypeInfoResolver, JsonContext.Default), 961Assert.Throws<InvalidOperationException>(() => AIJsonUtilities.DefaultOptions.AddAIContentType<DerivedAIContent>("derivativeContent")); 1008TypeInfoResolver = AIJsonUtilities.DefaultOptions.TypeInfoResolver 1011foreach (JsonSerializerOptions? options in new[] { AIJsonUtilities.DefaultOptions, null, customOptions }) 1013string key1 = AIJsonUtilities.HashDataToString(["a", 'b', 42], options); 1014string key2 = AIJsonUtilities.HashDataToString(["a", 'b', 42], options); 1015string key3 = AIJsonUtilities.HashDataToString([TimeSpan.FromSeconds(1), null, 1.23], options); 1016string key4 = AIJsonUtilities.HashDataToString([TimeSpan.FromSeconds(1), null, 1.23], options); 1017string key5 = AIJsonUtilities.HashDataToString([new Dictionary<string, object> { ["key1"] = 1, ["key2"] = 2 }], options); 1018string key6 = AIJsonUtilities.HashDataToString([new Dictionary<string, object> { ["key2"] = 2, ["key1"] = 1 }], options); 1031JsonSerializerOptions indentOptions = new(AIJsonUtilities.DefaultOptions) { WriteIndented = true }; 1032JsonSerializerOptions noIndentOptions = new(AIJsonUtilities.DefaultOptions) { WriteIndented = false }; 1035string key1 = AIJsonUtilities.HashDataToString([dict], indentOptions); 1036string key2 = AIJsonUtilities.HashDataToString([dict], noIndentOptions); 1047JsonElement schema = AIJsonUtilities.CreateFunctionJsonSchema(method.Method, inferenceOptions: new() 1096JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, options); 1130JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, options); 1165JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, options); 1202JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, options); 1229JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, options); 1248JsonElement schema = AIJsonUtilities.CreateJsonSchema(testData.Type, serializerOptions: options, inferenceOptions: createOptions); 1266JsonElement transformedSchema = AIJsonUtilities.TransformSchema(schema, transformOptions); 1293AIJsonUtilities.TransformSchema(transformedSchema, transformOptions); 1301Assert.Throws<ArgumentNullException>(() => AIJsonUtilities.TransformSchema(schema, transformOptions: null!)); 1302Assert.Throws<ArgumentException>(() => AIJsonUtilities.TransformSchema(schema, transformOptions: new())); 1315Assert.Throws<ArgumentException>(() => AIJsonUtilities.TransformSchema(schema, transformOptions)); 1336JsonSerializer.SerializeToNode(element1, AIJsonUtilities.DefaultOptions), 1337JsonSerializer.SerializeToNode(element2, AIJsonUtilities.DefaultOptions));
Microsoft.Extensions.AI.AzureAIInference (7)
AzureAIInferenceChatClient.cs (5)
329result.AdditionalProperties["top_k"] = new BinaryData(JsonSerializer.SerializeToUtf8Bytes(topK, AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(int)))); 336byte[] data = JsonSerializer.SerializeToUtf8Bytes(prop.Value, AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(object))); 456result = JsonSerializer.Serialize(resultContent.Result, AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(object))); 499JsonSerializer.Serialize(callRequest.Arguments, AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(IDictionary<string, object>)))))); 560(JsonTypeInfo<IDictionary<string, object>>)AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(IDictionary<string, object>)))!);
AzureAIInferenceEmbeddingGenerator.cs (1)
191byte[] data = JsonSerializer.SerializeToUtf8Bytes(prop.Value, AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(object)));
AzureAIInferenceImageEmbeddingGenerator.cs (1)
145byte[] data = JsonSerializer.SerializeToUtf8Bytes(prop.Value, AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(object)));
Microsoft.Extensions.AI.AzureAIInference.Tests (3)
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\AssertExtensions.cs (3)
62JsonSerializer.SerializeToNode(expectedJson, AIJsonUtilities.DefaultOptions), 63JsonSerializer.SerializeToNode(actualJson, AIJsonUtilities.DefaultOptions))) 75options ??= AIJsonUtilities.DefaultOptions;
Microsoft.Extensions.AI.Evaluation.Quality (2)
ChatMessageExtensions.cs (1)
24AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(ChatMessage)));
ChatResponseExtensions.cs (1)
39AIJsonUtilities.DefaultOptions.GetTypeInfo(contentType));
Microsoft.Extensions.AI.Evaluation.Reporting (1)
JsonSerialization\JsonUtilities.cs (1)
44options.TypeInfoResolverChain.Add(AIJsonUtilities.DefaultOptions.TypeInfoResolver!);
Microsoft.Extensions.AI.Evaluation.Reporting.Azure (1)
JsonSerialization\AzureStorageJsonUtilities.cs (1)
41options.TypeInfoResolverChain.Add(AIJsonUtilities.DefaultOptions.TypeInfoResolver!);
Microsoft.Extensions.AI.Integration.Tests (1)
ChatClientIntegrationTests.cs (1)
512public override JsonElement JsonSchema { get; } = JsonSerializer.Deserialize<JsonElement>(jsonSchema, AIJsonUtilities.DefaultOptions);
Microsoft.Extensions.AI.OpenAI (4)
OpenAIChatClient.cs (2)
152result = JsonSerializer.Serialize(resultContent.Result, AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(object))); 180fc.Arguments, AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(IDictionary<string, object?>))))));
OpenAIResponsesChatClient.cs (2)
517result = JsonSerializer.Serialize(resultContent.Result, AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(object))); 553AIJsonUtilities.DefaultOptions.GetTypeInfo(typeof(IDictionary<string, object?>)))));
Microsoft.Extensions.AI.OpenAI.Tests (3)
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\AssertExtensions.cs (3)
62JsonSerializer.SerializeToNode(expectedJson, AIJsonUtilities.DefaultOptions), 63JsonSerializer.SerializeToNode(actualJson, AIJsonUtilities.DefaultOptions))) 75options ??= AIJsonUtilities.DefaultOptions;
Microsoft.Extensions.AI.Tests (6)
ChatCompletion\FunctionInvokingChatClientTests.cs (1)
274JsonSerializer.SerializeToElement($"{e.GetString()} from delegate", AIJsonUtilities.DefaultOptions) :
Embeddings\DistributedCachingEmbeddingGeneratorTest.cs (1)
30Assert.Same(AIJsonUtilities.DefaultOptions, generator.JsonSerializerOptions);
Functions\AIFunctionFactoryTest.cs (1)
111JsonSerializerOptions options = new(AIJsonUtilities.DefaultOptions) { ReadCommentHandling = JsonCommentHandling.Skip };
test\Libraries\Microsoft.Extensions.AI.Abstractions.Tests\AssertExtensions.cs (3)
62JsonSerializer.SerializeToNode(expectedJson, AIJsonUtilities.DefaultOptions), 63JsonSerializer.SerializeToNode(actualJson, AIJsonUtilities.DefaultOptions))) 75options ??= AIJsonUtilities.DefaultOptions;