google-gemini/generative-ai-python

Support python `Literal` types when defining JSON or FunctionCalling schemas.

Opened this issue · 2 comments

Description of the feature request:

String literal types should create Enums in the generated schema.

What problem are you trying to solve with this feature?

No response

Any other information you'd like to share?

No response

@MarkDaoust you mention "generated" - is there a private method that generates protos.Schema somewhere ?

I was about to write a feature request for a from_object() like in node.js to convert a pydantic object to Schema.

Hi @yan-hic,

The code is here:

def _schema_for_class(cls: TypedDict) -> dict[str, Any]:
schema = _build_schema("dummy", {"dummy": (cls, pydantic.Field())})
return schema["properties"]["dummy"]
def _schema_for_function(

It uses pydantic to do the conversion already, but I haven't tested actually passing pydantic objects.
Similarly, I haven't tried this with types like Literal['a', 'b'].