Description
openedon Nov 16, 2024
Description
I built a C# code generator to implement the boilerplate for Tools/Agents/Functions.
I already generate at compile time the json schema string complying to the OpenAI specification for any agent.
The AIFunctionMetadata should provide a way to be initialized with the json schema directly.
Currently I can only specify (but there is no example, therefore I don't know how) the schema in AIFunctionReturnParameterMetadata
and AIFunctionParameterMetadata
.
Anyway, the problem with AIFunctionParameterMetadata
is that the json section specifying whether the parameter is required or not, belongs to the parent key (properties
). This means that even if I can initialize this class with each parameter schema, I cannot specify the required
field.
To get rid of all the problems and completely avoid the serialization at runtime, the root class AIFunctionMetadata should allow to take the entire schema. This also provides better performance.
Reproduction Steps
private AIFunctionMetadata CreateMetadata(
string functionName,
string functionDescription,
string returnSchema,
IEnumerable<(string name, string schema)> parametersSchema)
{
List<AIFunctionParameterMetadata> parameters = new();
foreach (var par in parametersSchema)
{
parameters.Add(new AIFunctionParameterMetadata(par.name)
{
Schema = par.schema,
});
}
// how can I specify the 'required' field for each parameter?
var returnParameter = new AIFunctionReturnParameterMetadata()
{
Schema = returnSchema,
};
var meta = new AIFunctionMetadata(functionName)
{
Description = functionDescription,
ReturnParameter = returnParameter,
Parameters = parameters,
};
return meta;
}
Expected behavior
I expect:
- to be able to initialize the
AIFunctionMetadata
with the entire schema, as for the OpenAI specification. - to be able to avoid any serialization or reflection in order to obtain better performance
Actual behavior
See example above: the ability to specify the schema per-parameter is not sufficient and does not provide any benefit
Regression?
No
Known Workarounds
Use reflection and serialize at runtime
Configuration
.NET 9.0.100
Other information
No response
Activity