Description
Description of the bug:
Body:
Hello,
I am encountering a persistent AttributeError: module 'google.generativeai' has no attribute 'Tool' even after extensive debugging, including a full virtual environment rebuild. The import path for the module appears to be correct, but the Tool attribute cannot be found.
-
Goal:
I am trying to use Function Calling with the Gemini API by defining a genai.Tool. -
The Error:
Traceback (most recent call last):
File "create_issue.py", line 58, in
genai.Tool(
^^^^^^^^^^
AttributeError: module 'google.generativeai' has no attribute 'Tool'
3. System & Library Information:
OS: Windows (using PowerShell)
pip show google-generativeai output:
Name: google-generativeai
Version: 0.8.5
Location: C:\Users\09801\Desktop\fountion coding\venv\Lib\site-packages
Import Path Check (genai.file output):
C:\Users\09801\Desktop\fountion coding\venv\Lib\site-packages\google\generativeai_init_.py
4. Code (create_issue.py):
Python
import os
import requests
import google.generativeai as genai
--- 1. Key Configuration ---
try:
genai.configure(api_key=os.environ["GOOGLE_API_KEY"])
GITHUB_TOKEN = os.environ["GITHUB_TOKEN"]
GITHUB_REPO = os.environ["GITHUB_REPO"]
except KeyError:
print("Error: Environment variables not set.")
exit()
--- 2. Function Definition ---
def create_github_issue(title: str, body: str, labels: list[str] = None):
# Function code... (as provided before)
pass
--- 3. Model and Tool Setup ---
tools = [
genai.Tool(
function_declarations=[
genai.FunctionDeclaration.from_func(create_github_issue)
]
)
]
model = genai.GenerativeModel(
model_name="gemini-1.5-flash",
tools=tools
)
print("Model and tools configured.")
Troubleshooting Steps Taken:
Confirmed library is up-to-date (v0.8.5).
Rebuilt the virtual environment from scratch (rm -rf venv, python -m venv venv, pip install ...).
Forced re-install without cache (pip install --force-reinstall --no-cache-dir ...).
Confirmed there is no local file named google.py that would cause a namespace collision.
Confirmed the module import path is correct using genai.file.
Despite all these steps, the AttributeError persists, suggesting a deeper issue with the library or its dependencies on my specific system. Any help would be appreciated.
Actual vs expected behavior:
No response
Any other information you'd like to share?
No response