This PR provides a thin wrapper around the Gemini client. Gemini provides structured generation by accepting the following to define output types:
A pydantic BaseModel. The output type is assumed to be JSON.
A TypedDict. The output type is assumed to be JSON.
A List type with a BaseModel or TypedDict argument. The output type is assumed to be a list of JSON objects.
An Enum. The output type is assumed to be one of the fields in the enum.
This integration is already fairly complex:
We need to define a new Choice output type to handle the Enum output type;
The Gemini SDK does not accept JSON Schema string. Json thus needs to keep track of the original definition object. We should thus add a method to translate the definition object to JSON Schema instead of translating during initialization.
The Gemini SDK also accepts TypedDicts
The Gemini SDK accepts List type with arguments.
TODO
[x] Handle list and List more elegantly
[x] Use Json to infer the type of the definition object / reject invalid definition objects
[x] Add Json method to convert the definition object to JSON Schema
[x] Use Choice to infer the type of the definition object / reject invalid definition objects
This PR provides a thin wrapper around the Gemini client. Gemini provides structured generation by accepting the following to define output types:
BaseModel
. The output type is assumed to be JSON.TypedDict
. The output type is assumed to be JSON.List
type with aBaseModel
orTypedDict
argument. The output type is assumed to be a list of JSON objects.Enum
. The output type is assumed to be one of the fields in the enum.This integration is already fairly complex:
Choice
output type to handle theEnum
output type;Json
thus needs to keep track of the original definition object. We should thus add a method to translate the definition object to JSON Schema instead of translating during initialization.TypedDict
sList
type with arguments.TODO
list
andList
more elegantlyJson
to infer the type of the definition object / reject invalid definition objectsJson
method to convert the definition object to JSON SchemaChoice
to infer the type of the definition object / reject invalid definition objectsBuilds on #1240.