Skip to content
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

feat(py): generate types.py from genkit-schema.json using datamodel-codegen #1807 #1808

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yesudeep
Copy link
Contributor

@yesudeep yesudeep commented Feb 3, 2025

feat: generate types.py from genkit-schema.json using datamodel-codegen #1807

ISSUE: #1807

CHANGELOG:

  • Add a bin/generate_schema_types script that generates the Pydantic
    types.py module.
  • Update the pre-commit hooks to ensure this file gets regenerated
    routinely.
  • Remove timestamp to ensure we do not treat a file with identical
    content differently preventing the hassles of updating this file per
    commit.

Checklist (if applicable):

@github-actions github-actions bot added feature New feature or request python Python config labels Feb 3, 2025
@yesudeep yesudeep force-pushed the yesudeep/feat/big-ticket branch from 5cbb967 to 8959150 Compare February 3, 2025 21:08
@yesudeep yesudeep requested a review from pavelgj February 3, 2025 21:09
@yesudeep yesudeep self-assigned this Feb 3, 2025
@yesudeep yesudeep added this to the py-0.1.0 milestone Feb 3, 2025
@yesudeep yesudeep changed the title feat: generate types.py from genkit-schema.json using datamodel-codegen #1807 feat(py): generate types.py from genkit-schema.json using datamodel-codegen #1807 Feb 3, 2025
@yesudeep yesudeep force-pushed the yesudeep/feat/big-ticket branch from 8959150 to 2c1dd96 Compare February 3, 2025 21:21
@yesudeep yesudeep requested a review from apascal07 February 3, 2025 21:49
)
text: Any | None = None
media: Any | None = None
toolRequest: Any | None = None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore if this is still in progress/intentional, but these types look off?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird. This is autogenerated, but let me take a look.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch Alex!

from pydantic import BaseModel, ConfigDict, Field, RootModel


class Model(RootModel[Any]):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please double check, but I believe this one was causing runtime errors before. Had to manually remove it.

totalTokens: float | None = None
inputCharacters: float | None = None
outputCharacters: float | None = None
inputImages: float | None = None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These seem off too.

@yesudeep yesudeep force-pushed the yesudeep/feat/big-ticket branch 5 times, most recently from b24d67f to 7723ab8 Compare February 4, 2025 07:36
…el-codegen #1807

    ISSUE: #1807

    CHANGELOG:
    - [ ] Add a bin/generate_schema_types script that generates the Pydantic
      types.py module.
    - [ ] Update the pre-commit hooks to ensure this file gets regenerated
      routinely.
    - [ ] Remove timestamp to ensure we do not treat a file with identical
      content differently preventing the hassles of updating this file per
    commit.
@yesudeep yesudeep force-pushed the yesudeep/feat/big-ticket branch from 7723ab8 to 2735ceb Compare February 4, 2025 23:01
index: float
message: Message
usage: Optional[GenerationUsage] = None
usage: GenerationUsage | None = None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a question: is GenerationUsage | None preferable to Optional[GenerationUsage]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the same thing in Python. The newer way of writing this is using type unions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
config feature New feature or request python Python
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants