-
Notifications
You must be signed in to change notification settings - Fork 761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose an AIJsonUtilities
class in M.E.AI and lower M.E.AI.Abstractions to STJv8
#5513
Merged
eiriktsarpalis
merged 11 commits into
dotnet:main
from
eiriktsarpalis:make-functioncallhelpers-public
Oct 17, 2024
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
68a9d45
Expose FunctionCallUtilities class.
eiriktsarpalis f6e6b98
Update src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/Fu…
eiriktsarpalis 514f846
Remove function call formatting helpers.
eiriktsarpalis aa76abf
Extract JSON schema inference settings into a separate options class.
eiriktsarpalis 1b1752b
Update src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/Js…
eiriktsarpalis fd85775
Address feedback
eiriktsarpalis 5ea90ed
Return FunctionCallContent in parser helpers.
eiriktsarpalis b02f38b
Address feedback
eiriktsarpalis 40f9ec8
Update src/Libraries/Microsoft.Extensions.AI/Functions/AIFunctionFact…
eiriktsarpalis 6e51c3d
Refactor to AIJsonUtilities class.
eiriktsarpalis b9dbf77
Move all utilities to M.E.AI and downgrade STJ version to 8 for M.E.A…
eiriktsarpalis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
395 changes: 0 additions & 395 deletions
395
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/FunctionCallHelpers.cs
This file was deleted.
Oops, something went wrong.
442 changes: 442 additions & 0 deletions
442
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/JsonFunctionCallUtilities.cs
Large diffs are not rendered by default.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/JsonSchemaInferenceOptions.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,30 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.Extensions.AI; | ||
|
||
/// <summary> | ||
/// An options class for configuring the behavior of <see cref="JsonFunctionCallUtilities"/> JSON schema inference functionality. | ||
/// </summary> | ||
public sealed class JsonSchemaInferenceOptions | ||
{ | ||
/// <summary> | ||
/// Gets the default options instance. | ||
/// </summary> | ||
public static JsonSchemaInferenceOptions Default { get; } = new JsonSchemaInferenceOptions(); | ||
|
||
/// <summary> | ||
/// Gets a value indicating whether to include the type keyword in inferred schemas for .NET enums. | ||
/// </summary> | ||
public bool IncludeTypeInEnumSchemas { get; init; } | ||
|
||
/// <summary> | ||
/// Gets a value indicating whether to generate schemas with the additionalProperties set to false for .NET objects. | ||
/// </summary> | ||
public bool DisallowAdditionalProperties { get; init; } | ||
|
||
/// <summary> | ||
/// Gets a value indicating whether to include the $schema keyword in inferred schemas. | ||
/// </summary> | ||
public bool IncludeSchemaKeyword { get; init; } | ||
} |
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
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be a separate change if we decide to do it, but should ToolCallJsonSerializerOptions be made non-nullable like it is on the middleware clients, just defaulting it to the default options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible, but it would require moving the defaults to
Abstractions
so that clients can reference it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not understanding why this would require any movement. I'm simply suggesting changing:
to
and then here instead of:
it'd just be:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless we're trying to avoid exposing this options instance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just pointing out that unless we expose a default options instance on
Abstractions
users will have to define their own contexts to fill in the default_toolCallOptions
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why. The current code doesn't require that, just substituting JsonContext.Default.Options when the user hasn't supplied their own. I'm simply suggesting moving around where we default back to that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you mean. It is appropriate to default to
JsonContext.Default.Options
in the particular locations where it is being done because they're serializing specific types (JsonElement
for FCR andIDictionary<string, object>
for FCC) which are known to be defined in the localJsonContext
. I don't think it would be safe to assume the same thing in other locations whereToolCallJsonSerializerOptions
is being used (e.g. when serializingAdditionalProperties
), so if we wanted to default to something in that case we should be using the global options instead.