Skip to content

Add support for non-string enums in Gemini #1564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 12, 2025

Conversation

zaidhaan
Copy link
Contributor

Closes #1553.

Gemini requires that enums must consist of only string members (e.g. currently IntEnum will cause a failure.). This PR modifies the _GeminiJsonSchema to reflect this, whilst still making it such that the output_type remains the correct type (e.g. IntEnum).

For an example, please reference the linked issue.

@zaidhaan
Copy link
Contributor Author

I might need a bit of assistance with setting up tests. Not too familiar with pytest and how it's used in this codebase. Or if someone is willing, there's an example in the linked issue that can be used as a test case.

@DouweM
Copy link
Contributor

DouweM commented Apr 30, 2025

@zaidhaan Thanks, the implementation looks good. Did you see the tests in tests/models/test_gemini.py? There are a few like test_json_def_date and test_json_def_replaced that you should be able to copy and modify to test the basic schema and then the Gemini-modified one. If you add a test to this PR, even if it's not working right yet, I can have a look at fixing it up.

@DouweM DouweM marked this pull request as draft April 30, 2025 19:27
@DouweM DouweM self-assigned this Apr 30, 2025
@tboser tboser mentioned this pull request May 6, 2025
@tboser
Copy link
Contributor

tboser commented May 6, 2025

hey @DouweM - I've also had this issue so went ahead and added a test for these changes here #1653 to get this over the line.

@zaidhaan
Copy link
Contributor Author

zaidhaan commented May 6, 2025

Hey, sorry for the late reply..! been a bit of a busy week for me.

Thanks for offering assistance @DouweM, I didn't notice that tests liketest_json_def_replaced had pretty much what I'd needed. I can see that your implementation @tboser pretty much does exactly that.

Not sure how we want to proceed though, seems tboser's PR had their runs cancelled for some reason.

EDIT: In the mean time, I'll cherry-pick your commit onto this branch and keep an eye on CI

@zaidhaan zaidhaan marked this pull request as ready for review May 6, 2025 20:44
@zaidhaan
Copy link
Contributor Author

zaidhaan commented May 6, 2025

I'm not sure why tests on 3.12 and 3.13 are failing. Seems to be occurring in other PRs too

@tboser
Copy link
Contributor

tboser commented May 6, 2025

Hey, sorry for the late reply..! been a bit of a busy week for me.

Thanks for offering assistance @DouweM, I didn't notice that tests liketest_json_def_replaced had pretty much what I'd needed. I can see that your implementation @tboser pretty much does exactly that.

Not sure how we want to proceed though, seems tboser's PR had their runs cancelled for some reason.

EDIT: In the mean time, I'll cherry-pick your commit onto this branch and keep an eye on CI

sweet no worries, didn't want to steal your work but excited to get this fix in!

@DouweM DouweM merged commit 1282f32 into pydantic:main May 12, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Gemini] IntEnum output not supported
3 participants