Skip to content

newly introduced google genai introduced unexpected dependency issue #1412

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

Closed
3 of 8 tasks
jingkaihe opened this issue Mar 16, 2025 · 7 comments
Closed
3 of 8 tasks
Assignees
Labels
bug Something isn't working

Comments

@jingkaihe
Copy link

jingkaihe commented Mar 16, 2025

  • This is actually a bug report.
  • I am not getting good LLM Results
  • I have tried asking for help in the community on discord or discussions and have not received a response.
  • I have tried searching the documentation and have not found an answer.

What Model are you using?

  • gpt-3.5-turbo
  • gpt-4-turbo
  • gpt-4
  • claude sonnet

Describe the bug

In my project I have googleapis-common-protos used by the open telemetry library, which has a google as the python package prefix.

The recently introduced genai support #1393 import the genai package as soon as it noticed the existence of google package https://github.com/instructor-ai/instructor/blob/cffd696e75a12e8803f30e7101a0216ea4680376/instructor/__init__.py#L110-L113

in this case without installing https://github.com/googleapis/python-genai library the instructor library failed to be initialised

To Reproduce
as soon as the instructor package is upgraded to ==1.7.5

I get

    import instructor
  File "/home/username/workspace/opsmate/.venv/lib/python3.12/site-packages/instructor/__init__.py", line 111, in <module>
    from .client_genai import from_genai
  File "/home/username/workspace/opsmate/.venv/lib/python3.12/site-packages/instructor/client_genai.py", line 6, in <module>
    from google.genai import Client
ModuleNotFoundError: No module named 'google.genai'

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

@github-actions github-actions bot added the bug Something isn't working label Mar 16, 2025
jingkaihe added a commit to opsmate-ai/opsmate that referenced this issue Mar 16, 2025
@tensoralex
Copy link

+1, same issue

@dehrman
Copy link

dehrman commented Mar 16, 2025

+1, same (importing instructor[vertex]). version-fixing Instructor back to 1.7.4 fixed it.

@ivanleomk
Copy link
Collaborator

I've managed to reproduce the issue with this code snippet ( terminal output shown below )

import instructor
from openai import OpenAI
from pydantic import BaseModel

class User(BaseModel):
    name: str
    age: int

client = instructor.from_openai(
    OpenAI(),
)

resp = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Ivan is 20 years old"}],
    response_model=User,
)

print(resp)

This was the set of terminal commands

ivanleo@Ivans-MacBook-Pro ~/D/c/test (main)> uv venv
Using CPython 3.12.7
Creating virtual environment at: .venv
Activate with: source .venv/bin/activate.fish
ivanleo@Ivans-MacBook-Pro ~/D/c/test (main)> uv pip install googleapis-common-protos instructor
Resolved 40 packages in 16ms
Installed 40 packages in 86ms
...
 + instructor==1.7.5
...
 + urllib3==2.3.0
 + yarl==1.18.3
ivanleo@Ivans-MacBook-Pro ~/D/c/test (main)> python3 ./main.py 
Traceback (most recent call last):
  File "/Users/ivanleo/Documents/coding/test/./main.py", line 1, in <module>
    import instructor
  File "/Users/ivanleo/Documents/coding/test/.venv/lib/python3.12/site-packages/instructor/__init__.py", line 111, in <module>
    from .client_genai import from_genai
  File "/Users/ivanleo/Documents/coding/test/.venv/lib/python3.12/site-packages/instructor/client_genai.py", line 6, in <module>
    from google.genai import Client
ModuleNotFoundError: No module named 'google.genai'

I've just merged in a PR for #1414 that fixes this ( as seen below when I install from the main branch )

ivanleo@Ivans-MacBook-Pro ~/D/c/test (main) [1]> uv pip install git+https://github.com/instructor-ai/instructor.git@main
 Updated https://github.com/instructor-ai/instructor.git (f1ba688)
Resolved 38 packages in 759ms
Uninstalled 1 package in 4ms
Installed 1 package in 2ms
 - instructor==1.7.5
 + instructor==1.7.5 (from git+https://github.com/instructor-ai/instructor.git@f1ba688554aace535b6088789d4f0a4f7ad911cb)
ivanleo@Ivans-MacBook-Pro ~/D/c/test (main)> python3 ./main.py
name='Ivan' age=20
ivanleo@Ivans-MacBook-Pro ~/D/c/test (main)> 

@ivanleomk
Copy link
Collaborator

Going to close this issue since 1.7.6 should solve it. Just verified on my end that with 1.7.6 this no longer gets thrown.

ivanleo@Ivans-MacBook-Pro ~/D/c/test (main)> uv pip install googleapis-common-protos instructor --upgrade
Resolved 40 packages in 230ms
Prepared 1 package in 114ms
Uninstalled 1 package in 6ms
Installed 1 package in 3ms
 - instructor==1.7.5 (from git+https://github.com/instructor-ai/instructor.git@f1ba688554aace535b6088789d4f0a4f7ad911cb)
 + instructor==1.7.6
ivanleo@Ivans-MacBook-Pro ~/D/c/test (main)> python3 ./main.py
name='Ivan' age=20
ivanleo@Ivans-MacBook-Pro ~/D/c/test (main)> uv pip list | grep genai

@ivanleomk
Copy link
Collaborator

Feel free to re-open if the issue persists, will debug! :)

@jingkaihe
Copy link
Author

can confirm the issue has been resolved. thanks for the speedy fix!

@ivanleomk
Copy link
Collaborator

ivanleomk commented Mar 17, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants