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

ImportError: "Please install google-generativeai and 'vertexai' to use Google's API" Despite Both Libraries Being Installed. #5132

Open
parth-sidgs opened this issue Jan 22, 2025 · 2 comments

Comments

@parth-sidgs
Copy link

parth-sidgs commented Jan 22, 2025

What happened?

While running the script autogen_code_reviewer.py that utilizes the autogen library, the following error occurred:
ImportError: Please install google-generativeai and 'vertexai' to use Google's API.

This error persists even after installing both google-generativeai and vertexai in the virtual environment. I verified both libraries using the pip show command. Also, the script was activated in a fresh virtual environment with all packages installed. The same code was running 2 days back, but suddenly throwing the above error.

What did you expect to happen?

The script should have executed without throwing the ImportError, as the necessary dependencies (google-generativeai and vertexai) were installed successfully. Specifically:

  1. The AssistantAgent initialization should proceed without issues.
  2. The script should begin generating and reviewing code as expected.

How can we reproduce it (as minimally and precisely as possible)?

  1. Activate the virtual environment.

  2. Install the necessary dependencies:
    pip install pyautogen google-generativeai vertexai autogen-agentchat~=0.2

  3. Run the following script:

import autogen
from autogen import AssistantAgent, UserProxyAgent

config_list = [
{
"model": "gemini-1.5-pro-002",
"api_type": "google",
"project_id": "my_project_id",
"location": "my_location"
}
]

code_generator = AssistantAgent(
name="code_generator",
llm_config={
"config_list": config_list,
"seed": 42,
"temperature": 0.7
},
system_message="""You are an expert code generator. Generate clean and well-documented code based on the requirements provided.""",
max_consecutive_auto_reply=2
)

Note: I authenticated with GCP using :gcloud auth application-default login, to use the Gemini model

AutoGen version

pyautogen version : 0.7.1

Which package was this bug in

Core

Model used

gemini-1.5-pro-002

Python version

3.12.5

Operating system

Windows 11

Any additional info you think would be helpful for fixing this bug

No response

@ekzhu
Copy link
Collaborator

ekzhu commented Jan 22, 2025

pyautogen version : 0.7.1

We just released 0.4.3, where does the 0.7 come from? 😉

Please uninstall pyautogen and update your autogen-agentchat package to the latest version is v0.4.3, it's recommended to use that version.

Also, Gemini has OpenAI Compatible Endpoint, it should be available through OpenAIChatCompletionClient, see example. https://microsoft.github.io/autogen/dev/reference/python/autogen_ext.models.openai.html#autogen_ext.models.openai.OpenAIChatCompletionClient

For the use case, you can use a two-agent chat with RoundRobinGroupChat instead.

@parth-sidgs
Copy link
Author

For pip show pyautogen-
it shows:
Name: pyautogen
Version: 0.7.1
Summary: A programming framework for agentic AI

Then i uninstalled pyautogen, and installed autogen (otherwise it throws module 'autogen' not found error)

Also upgraded autogen-agentchat, then did pip show autogen-agentchat -
output was:
Version: 0.4.3
Summary: AutoGen agents and teams library

Still getting the same error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants