Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions dotnet/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@
<PackageVersion Include="Microsoft.DeepDev.TokenizerLib" Version="1.3.3" />
<PackageVersion Include="SharpToken" Version="2.0.3" />
<!-- Microsoft.Extensions.* -->
<PackageVersion Include="Microsoft.Extensions.AI" Version="9.4.4-preview.1.25259.16" />
<PackageVersion Include="Microsoft.Extensions.AI.Abstractions" Version="9.4.4-preview.1.25259.16" />
<PackageVersion Include="Microsoft.Extensions.AI.AzureAIInference" Version="9.4.4-preview.1.25259.16" />
<PackageVersion Include="Microsoft.Extensions.AI.OpenAI" Version="9.4.4-preview.1.25259.16" />
<PackageVersion Include="Microsoft.Extensions.AI" Version="9.5.0-preview.1.25262.9" />
<PackageVersion Include="Microsoft.Extensions.AI.Abstractions" Version="9.5.0-preview.1.25262.9" />
<PackageVersion Include="Microsoft.Extensions.AI.AzureAIInference" Version="9.5.0-preview.1.25262.9" />
<PackageVersion Include="Microsoft.Extensions.AI.OpenAI" Version="9.5.0-preview.1.25262.9" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
// Copyright (c) Microsoft. All rights reserved.
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.Extensions.AI;
using Microsoft.SemanticKernel;

namespace Step04;

internal static class JsonSchemaGenerator
{
private static readonly AIJsonSchemaCreateOptions s_config = new()
{
TransformOptions = new()
{
DisallowAdditionalProperties = true,
RequireAllProperties = true,
MoveDefaultKeywordToDescription = true,
}
};

/// <summary>
/// Wrapper for generating a JSON schema as string from a .NET type.
/// </summary>
public static string FromType<TSchemaType>()
{
JsonSerializerOptions options = new(JsonSerializerOptions.Default)
{
UnmappedMemberHandling = JsonUnmappedMemberHandling.Disallow,
};
AIJsonSchemaCreateOptions config = new()
{
IncludeSchemaKeyword = false,
DisallowAdditionalProperties = true,
};

return KernelJsonSchemaBuilder.Build(typeof(TSchemaType), "Intent Result", config).AsJson();
return KernelJsonSchemaBuilder.Build(typeof(TSchemaType), "Intent Result", s_config).AsJson();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ namespace Microsoft.SemanticKernel.Connectors.Google.Core;
internal sealed class GeminiRequest
{
private static JsonSerializerOptions? s_options;
private static readonly AIJsonSchemaCreateOptions s_schemaOptions = new()
private static readonly AIJsonSchemaCreateOptions s_schemaConfiguration = new()
{
IncludeSchemaKeyword = false,
IncludeTypeInEnumSchemas = true,
RequireAllProperties = false,
DisallowAdditionalProperties = false,
TransformOptions = new()
{
UseNullableKeyword = true,
}
};

[JsonPropertyName("contents")]
Expand Down Expand Up @@ -319,11 +319,11 @@ private static void AddConfiguration(GeminiPromptExecutionSettings executionSett
var jsonElement = responseSchemaSettings switch
{
JsonElement element => element,
Type type => CreateSchema(type, GetDefaultOptions()),
Type type => CreateSchema(type, GetDefaultOptions(), configuration: s_schemaConfiguration),
KernelJsonSchema kernelJsonSchema => kernelJsonSchema.RootElement,
JsonNode jsonNode => JsonSerializer.SerializeToElement(jsonNode, GetDefaultOptions()),
JsonDocument jsonDocument => JsonSerializer.SerializeToElement(jsonDocument, GetDefaultOptions()),
_ => CreateSchema(responseSchemaSettings.GetType(), GetDefaultOptions())
_ => CreateSchema(responseSchemaSettings.GetType(), GetDefaultOptions(), configuration: s_schemaConfiguration)
};

jsonElement = TransformToOpenApi3Schema(jsonElement);
Expand Down Expand Up @@ -401,7 +401,7 @@ private static JsonElement CreateSchema(
string? description = null,
AIJsonSchemaCreateOptions? configuration = null)
{
configuration ??= s_schemaOptions;
configuration ??= s_schemaConfiguration;
return AIJsonUtilities.CreateJsonSchema(type, description, serializerOptions: options, inferenceOptions: configuration);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ public sealed class OpenAIJsonSchemaTransformerTests
{
private static readonly AIJsonSchemaCreateOptions s_jsonSchemaCreateOptions = new()
{
IncludeSchemaKeyword = false,
IncludeTypeInEnumSchemas = true,
DisallowAdditionalProperties = true,
RequireAllProperties = true,
TransformOptions = new()
{
DisallowAdditionalProperties = true,
RequireAllProperties = true,
MoveDefaultKeywordToDescription = true,
}
};

private static readonly JsonSerializerOptions s_jsonSerializerOptions = new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ internal static class OpenAIChatResponseFormatBuilder
/// </summary>
private static readonly Microsoft.Extensions.AI.AIJsonSchemaCreateOptions s_jsonSchemaCreateOptions = new()
{
IncludeSchemaKeyword = false,
IncludeTypeInEnumSchemas = true,
DisallowAdditionalProperties = true,
RequireAllProperties = true,
TransformOptions = new()
{
DisallowAdditionalProperties = true,
RequireAllProperties = true,
MoveDefaultKeywordToDescription = true,
}
};

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@ namespace Microsoft.SemanticKernel;
internal static class KernelJsonSchemaBuilder
{
private static JsonSerializerOptions? s_options;
internal static readonly AIJsonSchemaCreateOptions s_schemaOptions = new()
{
IncludeSchemaKeyword = false,
IncludeTypeInEnumSchemas = true,
RequireAllProperties = false,
DisallowAdditionalProperties = false,
};
internal static readonly AIJsonSchemaCreateOptions s_schemaOptions = new();

private static readonly JsonElement s_trueSchemaAsObject = JsonDocument.Parse("{}").RootElement;
private static readonly JsonElement s_falseSchemaAsObject = JsonDocument.Parse("""{"not":true}""").RootElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void ShouldAssignIsRequiredParameterMetadataPropertyCorrectly()
{
// Arrange and Act
AIFunction aiFunction = AIFunctionFactory.Create((string p1, int? p2 = null) => p1,
new AIFunctionFactoryOptions { JsonSchemaCreateOptions = new AIJsonSchemaCreateOptions { RequireAllProperties = false } });
new AIFunctionFactoryOptions { JsonSchemaCreateOptions = new AIJsonSchemaCreateOptions { TransformOptions = new() { RequireAllProperties = false } } });

AIFunctionKernelFunction sut = new(aiFunction);

Expand Down
Loading