Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for JsonSchema formatting in the Firebase AI library by adding a new JsonSchema class and integrating it into FunctionDeclaration and GenerationConfig for structured data definitions. The changes also include a new automated test case and minor cleanups in the existing Schema class. Review feedback points out a syntax error in FunctionCalling.cs involving a double semicolon and suggests refactoring the JsonSchema and Schema classes to use a common base class to reduce code duplication and improve maintainability.
| Name = name; | ||
| Description = description; | ||
| Parameters = null; | ||
| JsonParameters = JsonSchema.Object(parameters, optionalParameters);; |
| /// These types can be objects, but also primitives and arrays. Represents a select subset of an | ||
| /// [JsonSchema object](https://json-schema.org/specification). | ||
| /// </summary> | ||
| public class JsonSchema |
There was a problem hiding this comment.
This new JsonSchema class is almost a complete duplicate of the existing Schema class. This introduces a significant amount of code duplication, which will make future maintenance harder, as bug fixes and enhancements will need to be applied in two places.
Consider refactoring to reduce duplication. One approach would be to create a generic base class (e.g., SchemaBase<T>) that contains the common logic, and then have both Schema and JsonSchema inherit from it.
For example:
public abstract class SchemaBase<T> where T : SchemaBase<T>
{
// ... common properties like Type, Description, etc.
// Properties that refer to the schema type would use T
public T Items { get; }
public IReadOnlyDictionary<string, T> Properties { get; }
// ...
protected SchemaBase(...) { /* ... */ }
}
public class JsonSchema : SchemaBase<JsonSchema>
{
// ... JsonSchema specific logic and factory methods
}
public class Schema : SchemaBase<Schema>
{
// ... Schema specific logic and factory methods
}This would greatly improve the maintainability of the code.
Description
Add the JsonSchema class, which is mostly a duplicate of the Schema object, which follows the OpenAPI schema. They support refs and defs, for Object definition.
Testing
Running tests locally.
Type of Change
Place an
xthe applicable box: