Skip to content
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,42 @@ public static void CreateFunctionJsonSchema_ReturnsExpectedValue()
Assert.True(DeepEquals(resolvedSchema, func.JsonSchema));
}

[Fact]
public static void CreateFunctionJsonSchema_OptionalParameters_ShouldNotBeRequired()
{
JsonElement expected = JsonDocument.Parse("""
{
"title": "get_weather",
"description": "Gets the current weather for a current location",
"type": "object",
"properties": {
"city": {
"description": "The city to get the weather for",
"type": "string"
},
"unit": {
"description": "The unit to calculate the current temperature to (Default value: \u0022celsius\u0022)",
"type": "string"
}
},
"required": [
"city"
]
}
""").RootElement;

JsonSerializerOptions options = new(AIJsonUtilities.DefaultOptions);
AIFunction func = AIFunctionFactory.Create((
[Description("The city to get the weather for")] string city,
[Description("The unit to calculate the current temperature to")] string unit = "celsius") => "sunny",
"get_weather", "Gets the current weather for a current location");

Assert.NotNull(func.UnderlyingMethod);

JsonElement resolvedSchema = AIJsonUtilities.CreateFunctionJsonSchema(func.UnderlyingMethod, title: func.Name, description: func.Description);
Assert.True(DeepEquals(expected, resolvedSchema));
}

[Fact]
public static void CreateFunctionJsonSchema_TreatsIntegralTypesAsInteger_EvenWithAllowReadingFromString()
{
Expand Down
Loading