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

Consider adding py.typed to repo to support type checking #4654

Open
acciaioli opened this issue Nov 14, 2024 · 1 comment · May be fixed by #4700
Open

Consider adding py.typed to repo to support type checking #4654

acciaioli opened this issue Nov 14, 2024 · 1 comment · May be fixed by #4700
Labels
api: vertex-ai Issues related to the googleapis/python-aiplatform API.

Comments

@acciaioli
Copy link

acciaioli commented Nov 14, 2024

Is your feature request related to a problem? Please describe.
Despite being typed, this package doesnt include a py.typed file.
As a user, i am struggling to benefit from the defined types

Consider the code featured in the quickstart page

import vertexai
from vertexai.generative_models import GenerativeModel

# TODO(developer): Update and un-comment below line
PROJECT_ID = "your-project-id"
vertexai.init(project=PROJECT_ID, location="us-central1")

model = GenerativeModel("gemini-1.5-flash-002")
reveal_type(model)
response = model.generate_content(
    "What's a good name for a flower shop that specializes in selling bouquets of dried flowers?"
)
reveal_type(response)
print(response.text)
►mypy
scripts/gc_sdk.py:1: error: Skipping analyzing "vertexai": module is installed, but missing library stubs or py.typed marker  [import-untyped]
scripts/gc_sdk.py:2: error: Skipping analyzing "vertexai.generative_models": module is installed, but missing library stubs or py.typed marker  [import-untyped]
scripts/gc_sdk.py:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
scripts/gc_sdk.py:9: note: Revealed type is "Any"
scripts/gc_sdk.py:13: note: Revealed type is "Any"

And if I add the py.typed manually..

►mypy
scripts/gc_sdk.py:9: note: Revealed type is "vertexai.generative_models._generative_models.GenerativeModel"
scripts/gc_sdk.py:13: note: Revealed type is "vertexai.generative_models._generative_models.GenerationResponse"
Found 2 errors in 1 file (checked 48 source files)

This would help find issues using the lib, for example:

model = GenerativeModel("gemini-1.5-flash", version="002") 
scripts/gc_sdk.py:8: error: Unexpected keyword argument "version" for "GenerativeModel"  [call-arg]

Describe the solution you'd like
I would like you to consider adding a empty file py.typed inside the vertexai directory

Describe alternatives you've considered
I am considering creating the py.typed just before I ran mypy in my CI
This way, I could use this lib with type safety

Additional context

@product-auto-label product-auto-label bot added the api: vertex-ai Issues related to the googleapis/python-aiplatform API. label Nov 14, 2024
@vladimir-chernykh
Copy link

Hey!

I've just faced the same issue and made a PR here: #4700

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: vertex-ai Issues related to the googleapis/python-aiplatform API.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants