feat: add parameter attribute to allow customization of name, description, and requiredness
This commit is contained in:
@@ -42,4 +42,58 @@ public class JsonSchemaGeneratorTests
|
||||
|
||||
JsonAssert.Equal(expectedSchema, schema);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GenerateInputSchema_GivenFunctionWithParameterThatDoesNotHaveDefaultValue_ItShouldReturnSchemaWithPropertyNameDescriptionAndRequiredProperties()
|
||||
{
|
||||
var expectedSchema = new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["name"] = new JsonObject()
|
||||
{
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"name"
|
||||
},
|
||||
};
|
||||
|
||||
var testMethod = (string name) => name;
|
||||
var function = new AnthropicFunction(testMethod.Method);
|
||||
|
||||
var schema = JsonSchemaGenerator.GenerateInputSchema(function);
|
||||
|
||||
JsonAssert.Equal(expectedSchema, schema);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GenerateInputSchema_GivenFunctionWithParameterThatHasAttribute_ItShouldReturnSchemaWithCorrectPropertyNameDescriptionAndRequiredProperty()
|
||||
{
|
||||
var expectedSchema = new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["Person's Age"] = new JsonObject()
|
||||
{
|
||||
["description"] = "The age of the person."
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"Person's Age"
|
||||
},
|
||||
};
|
||||
|
||||
var testMethod = ([FunctionParameter("The age of the person.", "Person's Age", true)] int name) => name;
|
||||
var function = new AnthropicFunction(testMethod.Method);
|
||||
|
||||
var schema = JsonSchemaGenerator.GenerateInputSchema(function);
|
||||
|
||||
JsonAssert.Equal(expectedSchema, schema);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user