-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.Net: Make ONNX connector Native-AOT compatible. (#9192)
### Motivation and Context This PR makes the ONNX connector Native-AOT friendly, allowing it to be used in applications targeting Native-AOT. ### Description - Adds a new parameter of `JsonSerializerOptions` type to the constructor of the `OnnxRuntimeGenAIChatCompletionService` class and a few extension methods. - Adds a new `OnnxRuntimeGenAIPromptExecutionSettings.FromExecutionSettings` method that accepts JSOs to serialize prompt execution settings type of which is not known in advance. - Makes function choice behavior classes public, allowing the source generator to access them and not fail with the error: "_dotnet\src\Connectors\Connectors.Onnx\Text\OnnxRuntimeGenAIPromptExecutionSettingsJsonSerializerContext - Copy.cs(10,31,10,91): warning SYSLIB1222: The constructor on type 'Microsoft.SemanticKernel.AutoFunctionChoiceBehavior' has been annotated with JsonConstructorAttribute but is not accessible by the source generator. (https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/syslib1222)_" CC: @eiriktsarpalis
- Loading branch information
1 parent
c029612
commit 47a2ad3
Showing
15 changed files
with
201 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
dotnet/src/Connectors/Connectors.Onnx.UnitTests/CustomPromptExecutionSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System.Text.Json.Serialization; | ||
using Microsoft.SemanticKernel; | ||
|
||
namespace SemanticKernel.Connectors.Onnx.UnitTests; | ||
|
||
internal sealed class CustomPromptExecutionSettings : PromptExecutionSettings | ||
{ | ||
/// <summary> | ||
/// Temperature to sample with. | ||
/// </summary> | ||
[JsonPropertyName("temperature")] | ||
public float? Temperature { get; set; } | ||
} |
10 changes: 10 additions & 0 deletions
10
...onnectors/Connectors.Onnx.UnitTests/CustomPromptExecutionSettingsJsonSerializerContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System.Text.Json.Serialization; | ||
|
||
namespace SemanticKernel.Connectors.Onnx.UnitTests; | ||
|
||
[JsonSerializable(typeof(CustomPromptExecutionSettings))] | ||
internal sealed partial class CustomPromptExecutionSettingsJsonSerializerContext : JsonSerializerContext | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...tors/Connectors.Onnx/Text/OnnxRuntimeGenAIPromptExecutionSettingsJsonSerializerContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using Microsoft.SemanticKernel.Connectors.Onnx; | ||
|
||
namespace Microsoft.SemanticKernel.Text; | ||
|
||
[JsonSerializable(typeof(OnnxRuntimeGenAIPromptExecutionSettings))] | ||
internal sealed partial class OnnxRuntimeGenAIPromptExecutionSettingsJsonSerializerContext : JsonSerializerContext | ||
{ | ||
public static readonly OnnxRuntimeGenAIPromptExecutionSettingsJsonSerializerContext ReadPermissive = new(new() | ||
{ | ||
AllowTrailingCommas = true, | ||
PropertyNameCaseInsensitive = true, | ||
ReadCommentHandling = JsonCommentHandling.Skip, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.