generative-ai-python icon indicating copy to clipboard operation
generative-ai-python copied to clipboard

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

Open MarkDaoust opened this issue 1 year ago • 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 avatar Sep 30 '24 17:09 MarkDaoust

@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.

yan-hic avatar Oct 04 '24 07:10 yan-hic

Hi @yan-hic,

The code is here:

https://github.com/google-gemini/generative-ai-python/blob/8f77cc6ac99937cd3a81299ecf79608b91b06bbb/google/generativeai/types/content_types.py#L337-L342

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'].

MarkDaoust avatar Oct 04 '24 16:10 MarkDaoust

These seem to work, as long as they're nested inside a class, just not at the top level.

MarkDaoust avatar Feb 19 '25 14:02 MarkDaoust