-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
.Net InputVariable.Default type is changed from string to object? #4345
Merged
Conversation
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
stephentoub
reviewed
Dec 18, 2023
dotnet/src/SemanticKernel.Abstractions/PromptTemplate/PromptTemplateConfig.cs
Outdated
Show resolved
Hide resolved
stephentoub
reviewed
Dec 18, 2023
dotnet/src/SemanticKernel.Abstractions/PromptTemplate/PromptTemplateConfig.cs
Outdated
Show resolved
Hide resolved
stephentoub
reviewed
Dec 18, 2023
dotnet/src/Extensions/PromptTemplates.Handlebars/HandlebarsPromptTemplate.cs
Outdated
Show resolved
Hide resolved
stephentoub
reviewed
Dec 18, 2023
stephentoub
approved these changes
Dec 18, 2023
markwallace-microsoft
approved these changes
Dec 18, 2023
dotnet/src/Functions/Functions.UnitTests/Yaml/Functions/KernelFunctionYamlTests.cs
Outdated
Show resolved
Hide resolved
dotnet/src/SemanticKernel.Abstractions/PromptTemplate/PromptTemplateConfig.cs
Outdated
Show resolved
Hide resolved
dotnet/src/SemanticKernel.UnitTests/PromptTemplate/PromptTemplateConfigTests.cs
Show resolved
Hide resolved
RogerBarreto
approved these changes
Dec 18, 2023
dotnet/src/Extensions/PromptTemplates.Handlebars/HandlebarsPromptTemplate.cs
Outdated
Show resolved
Hide resolved
dotnet/src/SemanticKernel.Abstractions/PromptTemplate/PromptTemplateConfig.cs
Outdated
Show resolved
Hide resolved
markwallace-microsoft
approved these changes
Dec 18, 2023
RogerBarreto
approved these changes
Dec 18, 2023
Kevdome3000
pushed a commit
to Kevdome3000/semantic-kernel
that referenced
this pull request
Dec 18, 2023
…crosoft#4345) ### Motivation and Context The SK is no longer string-centric and can now work with any .NET type, including strings. Functions can have parameters and return types of any type. Prompt variables can also be of any type. The last remaining element tied to the string type is the `InputVariable.Default` property. This PR addresses that. ### Description - The `InputVariable.Default` property type changed from string to object. - All instances where the property is used are refactored accordingly. Where the string value of the property is required, it is converted to a string; in other cases, it is used as is. - Safeguards that prevent supplying default values of any type other than string in JSON and YAML prompt configurations are temporarily added until a proper, permanent solution is designed and implemented. More details below. ### JsonSerializer & DeserializerBuilder handling primitives, objects, and arrays Both JsonSerializer and DeserializerBuilder (from YamlDotNet) can infer the types of properties of the data model class into which they deserialize a string when a concrete, non-object type is specified. However, when the target type of a property is `object`, each attempts to accomplish deserialization differently. The JsonSerializer, when deserializing to a property of `object` type, assigns a JsonElement (configurable, can be JsonNode) to the property, regardless of whether the type specified in the JSON is a primitive, array, or object. The DeserializerBuilder deserializes all primitives as strings unless the `!!type` tag is used - `!!int`, `!!bool`, etc. As for complex types and arrays, those are deserialized as `Dictionary<object, object>` and `List<object>`, respectively. Taking that into account, the solution should address the problem of having or using different types to represent the same data. The different types can be adapted to: - One universal data type for JSON/YAML objects (perhaps JsonElement?) - `List<object>` for JSON/YAML arrays - .NET primitives for JSON and YAML primitives - number, boolean, string This way, function authors can write their functions regardless of whether the function is called from a JSON prompt or a YAML prompt. ### Default value and schema In addition to standard attributes/properties of function parameter metadata such as name, description, isRequired, and default, it's possible to specify a [JSON schema](https://json-schema.org/) to add extra information about the type of root and nested elements. Ideally, the solution should take the schema into account, if specified, and use the type indicated there to convert the default value to at deserialization. In cases where the schema is not provided, the functionality should rely solely on the data types provided in JSON/YAML documents. (cherry picked from commit 3eaa507)
Kevdome3000
pushed a commit
to Kevdome3000/semantic-kernel
that referenced
this pull request
Dec 18, 2023
…crosoft#4345) ### Motivation and Context The SK is no longer string-centric and can now work with any .NET type, including strings. Functions can have parameters and return types of any type. Prompt variables can also be of any type. The last remaining element tied to the string type is the `InputVariable.Default` property. This PR addresses that. ### Description - The `InputVariable.Default` property type changed from string to object. - All instances where the property is used are refactored accordingly. Where the string value of the property is required, it is converted to a string; in other cases, it is used as is. - Safeguards that prevent supplying default values of any type other than string in JSON and YAML prompt configurations are temporarily added until a proper, permanent solution is designed and implemented. More details below. ### JsonSerializer & DeserializerBuilder handling primitives, objects, and arrays Both JsonSerializer and DeserializerBuilder (from YamlDotNet) can infer the types of properties of the data model class into which they deserialize a string when a concrete, non-object type is specified. However, when the target type of a property is `object`, each attempts to accomplish deserialization differently. The JsonSerializer, when deserializing to a property of `object` type, assigns a JsonElement (configurable, can be JsonNode) to the property, regardless of whether the type specified in the JSON is a primitive, array, or object. The DeserializerBuilder deserializes all primitives as strings unless the `!!type` tag is used - `!!int`, `!!bool`, etc. As for complex types and arrays, those are deserialized as `Dictionary<object, object>` and `List<object>`, respectively. Taking that into account, the solution should address the problem of having or using different types to represent the same data. The different types can be adapted to: - One universal data type for JSON/YAML objects (perhaps JsonElement?) - `List<object>` for JSON/YAML arrays - .NET primitives for JSON and YAML primitives - number, boolean, string This way, function authors can write their functions regardless of whether the function is called from a JSON prompt or a YAML prompt. ### Default value and schema In addition to standard attributes/properties of function parameter metadata such as name, description, isRequired, and default, it's possible to specify a [JSON schema](https://json-schema.org/) to add extra information about the type of root and nested elements. Ideally, the solution should take the schema into account, if specified, and use the type indicated there to convert the default value to at deserialization. In cases where the schema is not provided, the functionality should rely solely on the data types provided in JSON/YAML documents. (cherry picked from commit 3eaa507)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation and Context
The SK is no longer string-centric and can now work with any .NET type, including strings. Functions can have parameters and return types of any type. Prompt variables can also be of any type. The last remaining element tied to the string type is the
InputVariable.Default
property. This PR addresses that.Description
InputVariable.Default
property type changed from string to object.JsonSerializer & DeserializerBuilder handling primitives, objects, and arrays
Both JsonSerializer and DeserializerBuilder (from YamlDotNet) can infer the types of properties of the data model class into which they deserialize a string when a concrete, non-object type is specified. However, when the target type of a property is
object
, each attempts to accomplish deserialization differently.The JsonSerializer, when deserializing to a property of
object
type, assigns a JsonElement (configurable, can be JsonNode) to the property, regardless of whether the type specified in the JSON is a primitive, array, or object.The DeserializerBuilder deserializes all primitives as strings unless the
!!type
tag is used -!!int
,!!bool
, etc. As for complex types and arrays, those are deserialized asDictionary<object, object>
andList<object>
, respectively.Taking that into account, the solution should address the problem of having or using different types to represent the same data. The different types can be adapted to:
List<object>
for JSON/YAML arraysThis way, function authors can write their functions regardless of whether the function is called from a JSON prompt or a YAML prompt.
Default value and schema
In addition to standard attributes/properties of function parameter metadata such as name, description, isRequired, and default, it's possible to specify a JSON schema to add extra information about the type of root and nested elements.
Ideally, the solution should take the schema into account, if specified, and use the type indicated there to convert the default value to at deserialization. In cases where the schema is not provided, the functionality should rely solely on the data types provided in JSON/YAML documents.