feat: implement json schema generation for non-complex types

This commit is contained in:
Stevan Freeborn
2024-06-30 13:57:35 -05:00
parent 4fd8ecd96b
commit 96ed89c9ce
3 changed files with 595 additions and 12 deletions
@@ -1,6 +1,6 @@
using System.Text.Json.Nodes;
namespace AnthropicClient.Tests.Unit.Models;
namespace AnthropicClient.Tests.Unit.Utils;
public class JsonSchemaGeneratorTests
{
@@ -96,4 +96,30 @@ public class JsonSchemaGeneratorTests
JsonAssert.Equal(expectedSchema, schema);
}
[Fact]
public void GenerateInputSchema_GivenFunctionWithParametersThatIncludesCancellationToken_ItShouldReturnSchemaWithoutCancellationToken()
{
var expectedSchema = new JsonObject()
{
["type"] = "object",
["properties"] = new JsonObject(),
["required"] = new JsonArray(),
};
var testMethod = (CancellationToken token) => true;
var function = new AnthropicFunction(testMethod.Method);
var schema = JsonSchemaGenerator.GenerateInputSchema(function);
JsonAssert.Equal(expectedSchema, schema);
}
[Theory]
[ClassData(typeof(JsonSchemaGeneratorTestData))]
public void GenerateInputSchema_GivenFunction_ItShouldReturnExpectedSchema(Tool tool, JsonObject expectedSchema)
{
var schema = JsonSchemaGenerator.GenerateInputSchema(tool.Function);
JsonAssert.Equal(expectedSchema, schema);
}
}