crewAIInc / crewAI

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.
https://crewai.com
MIT License
20.74k stars 2.87k forks source link

BUG while using GEMINI from google as an llm in the agent #879

Closed atb29 closed 3 months ago

atb29 commented 4 months ago

i got an error that says you have to provide the openai api key even if im using gemini as llm in the agent , (im using the last version of crewai , python 3.10) , here is the main script


from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_community.tools import DuckDuckGoSearchRun
from dotenv import load_dotenv

load_dotenv()

import os 
GOOGLE_API_KEY=os.getenv("GOOGLE_API_KEY")

# Define agents with specific roles and tools
researcher = Agent(
    role='Senior Research Analyst',
    goal='Discover innovative AI technologies',
    backstory="""You're a senior research analyst at a large company.
        You're responsible for analyzing data and providing insights
        to the business.
        You're currently working on a project to analyze the
        trends and innovations in the space of artificial intelligence.""",
    llm = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=GOOGLE_API_KEY),
    tools=[DuckDuckGoSearchRun()]
)

writer = Agent(
    role='Content Writer',
    goal='Write engaging articles on AI discoveries',
    backstory="""You're a senior writer at a large company.
        You're responsible for creating content to the business.
        You're currently working on a project to write about trends
        and innovations in the space of AI for your next meeting.""",
    llm = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=GOOGLE_API_KEY),
    verbose=True
)

# Create tasks for the agents
research_task = Task(
    description='Identify breakthrough AI technologies',
    agent=researcher,
    expected_output='A bullet list summary of the top 5 most important AI news'
)
write_article_task = Task(
    description='Draft an article on the latest AI technologies',
    agent=writer,
    expected_output='3 paragraph blog post on the latest AI technologies'
)

# Assemble the crew with a sequential process
my_crew = Crew(
    agents=[researcher, writer],
    tasks=[research_task, write_article_task],
    process=Process.sequential,
    full_output=True,
    verbose=True,
)

# Example of using kickoff_for_each
inputs_array = [{'topic': 'AI in healthcare'}, {'topic': 'AI in finance'}]
results = my_crew.kickoff_for_each(inputs=inputs_array)
for result in results:
    print(result)"""

    and here is the error i got :
    """Traceback (most recent call last):
  File "C:\Users\ATIBI\Desktop\memory_framework\main.txt", line 58, in <module>
    results = my_crew.kickoff_for_each(inputs=inputs_array)
  File "C:\Users\ATIB\Desktop\memory_framework\myenv\lib\site-packages\crewai\crew.py", line 335, in kickoff_for_each
    crew = self.copy()
  File "C:\Users\ATIB\Desktop\memory_framework\myenv\lib\site-packages\crewai\crew.py", line 484, in copy
    cloned_agents = [agent.copy() for agent in self.agents]
  File "C:\Users\ATIB\Desktop\memory_framework\myenv\lib\site-packages\crewai\crew.py", line 484, in <listcomp>
    cloned_agents = [agent.copy() for agent in self.agents]
  File "C:\Users\ATIB\Desktop\memory_framework\myenv\lib\site-packages\crewai\agents\agent_builder\base_agent.py", line 235, in copy
    copied_agent = self.__class__(**copied_data)
  File "C:\Users\ATIB\Desktop\memory_framework\myenv\lib\site-packages\crewai\agent.py", line 86, in __init__
    super().__init__(**config, **data)
  File "C:\Users\ATIB\Desktop\memory_framework\myenv\lib\site-packages\crewai\agents\agent_builder\base_agent.py", line 124, in __init__
    super().__init__(**config, **data)
  File "C:\Users\ATIB\Desktop\memory_framework\myenv\lib\site-packages\pydantic\main.py", line 176, in __init__
    self.__pydantic_validator__.validate_python(data, self_instance=self)
  File "C:\Users\ATIB\Desktop\memory_framework\myenv\lib\site-packages\crewai\agent.py", line 59, in <lambda>
    default_factory=lambda: ChatOpenAI(
  File "C:\Users\ATIB\Desktop\memory_framework\myenv\lib\site-packages\pydantic\v1\main.py", line 341, in __init__
    raise validation_error
pydantic.v1.error_wrappers.ValidationError: 1 validation error for ChatOpenAI
__root__
  Did not find openai_api_key, please add an environment variable `OPENAI_API_KEY` which contains it, or pass `openai_api_key` as a named parameter. (type=value_error)```
bhancockio commented 4 months ago

Hey @atb29

Which version of CrewAI are you using? We've shipped a lot of improvements and fixed a ton of bugs over the past week so I'm hoping the new version will fix the issue you're running into.

As of this message, the latest version of CrewAI is v0.35.8

Could you also run pip freeze and share the results with me so I can see the version numbers of your other dependencies?

theCyberTech commented 4 months ago

Hi @atb29 ,

We have just cut a new version that fixes this bug, could you please update and let us no how you go. I would recommend uninstalling crewai and installing with pip install crewai --no-cache-dir

atb29 commented 3 months ago

here are the dependencies guys !!

(myenv) C:\Users\ATIB\Desktop\memory_framework>pip freeze aiohttp==3.9.5 aiosignal==1.3.1 alembic==1.13.2 annotated-types==0.7.0 anyio==4.4.0 appdirs==1.4.4 asgiref==3.8.1 async-timeout==4.0.3 attrs==23.2.0 backoff==2.2.1 bcrypt==4.1.3 beautifulsoup4==4.12.3 boto3==1.34.135 botocore==1.34.135 build==1.2.1 cachetools==5.3.3 certifi==2024.6.2 charset-normalizer==3.3.2 chroma-hnswlib==0.7.3 chromadb==0.4.24 clarifai==10.5.3 clarifai-grpc==10.6.1 click==8.1.7 cohere==5.5.8 colorama==0.4.6 coloredlogs==15.0.1 contextlib2==21.6.0 crewai==0.36.0 dataclasses-json==0.6.7 Deprecated==1.2.14 distro==1.9.0 dnspython==2.6.1 docstring_parser==0.16 duckduckgo_search==6.1.7 email_validator==2.2.0 embedchain==0.1.115 exceptiongroup==1.2.1 fastapi==0.111.0 fastapi-cli==0.0.4 fastavro==1.9.4 filelock==3.15.4 flatbuffers==24.3.25 frozenlist==1.4.1 fsspec==2024.6.1 google-ai-generativelanguage==0.6.6 google-api-core==2.19.1 google-api-python-client==2.135.0 google-auth==2.30.0 google-auth-httplib2==0.2.0 google-cloud-aiplatform==1.57.0 google-cloud-bigquery==3.25.0 google-cloud-core==2.4.1 google-cloud-resource-manager==1.12.3 google-cloud-storage==2.17.0 google-crc32c==1.5.0 google-generativeai==0.7.1 google-resumable-media==2.7.1 googleapis-common-protos==1.63.2 gptcache==0.1.43 greenlet==3.0.3 grpc-google-iam-v1==0.13.1 grpcio==1.64.1 grpcio-status==1.62.2 h11==0.14.0 httpcore==1.0.5 httplib2==0.22.0 httptools==0.6.1 httpx==0.27.0 httpx-sse==0.4.0 huggingface-hub==0.23.4 humanfriendly==10.0 idna==3.7 importlib_metadata==7.1.0 importlib_resources==6.4.0 inquirerpy==0.3.4 instructor==1.3.3 Jinja2==3.1.4 jiter==0.4.2 jmespath==1.0.1 jsonpatch==1.33 jsonpointer==3.0.0 jsonref==1.1.0 kubernetes==30.1.0 langchain==0.2.6 langchain-cohere==0.1.5 langchain-community==0.2.6 langchain-core==0.2.10 langchain-google-genai==1.0.7 langchain-openai==0.1.7 langchain-text-splitters==0.2.2 langsmith==0.1.82 Mako==1.3.5 markdown-it-py==3.0.0 MarkupSafe==2.1.5 marshmallow==3.21.3 mdurl==0.1.2 mmh3==4.1.0 monotonic==1.6 mpmath==1.3.0 multidict==6.0.5 mypy-extensions==1.0.0 numpy==1.26.4 oauthlib==3.2.2 onnxruntime==1.18.1 openai==1.35.7 opentelemetry-api==1.25.0 opentelemetry-exporter-otlp-proto-common==1.25.0 opentelemetry-exporter-otlp-proto-grpc==1.25.0 opentelemetry-exporter-otlp-proto-http==1.25.0 opentelemetry-instrumentation==0.46b0 opentelemetry-instrumentation-asgi==0.46b0 opentelemetry-instrumentation-fastapi==0.46b0 opentelemetry-proto==1.25.0 opentelemetry-sdk==1.25.0 opentelemetry-semantic-conventions==0.46b0 opentelemetry-util-http==0.46b0 orjson==3.10.5 overrides==7.7.0 packaging==23.2 parameterized==0.9.0 pfzy==0.3.4 pillow==10.4.0 posthog==3.5.0 prompt_toolkit==3.0.47 proto-plus==1.24.0 protobuf==4.25.3 pulsar-client==3.5.0 pyasn1==0.6.0 pyasn1_modules==0.4.0 pydantic==2.7.4 pydantic_core==2.18.4 Pygments==2.18.0 pyparsing==3.1.2 pypdf==4.2.0 PyPika==0.48.9 pyproject_hooks==1.1.0 pyreadline3==3.4.1 pyreqwest_impersonate==0.4.8 pysbd==0.3.4 python-dateutil==2.9.0.post0 python-dotenv==1.0.1 python-multipart==0.0.9 python-rapidjson==1.18 PyYAML==6.0.1 regex==2023.12.25 requests==2.32.3 requests-oauthlib==2.0.0 rich==13.7.1 rsa==4.9 s3transfer==0.10.2 schema==0.7.5 shapely==2.0.4 shellingham==1.5.4 six==1.16.0 sniffio==1.3.1 soupsieve==2.5 SQLAlchemy==2.0.31 starlette==0.37.2 sympy==1.12.1 tabulate==0.9.0 tenacity==8.4.2 tiktoken==0.7.0 tokenizers==0.19.1 tomli==2.0.1 tqdm==4.66.4 tritonclient==2.47.0 typer==0.12.3 types-requests==2.32.0.20240622 typing-inspect==0.9.0 typing_extensions==4.12.2 ujson==5.10.0 uritemplate==4.1.1 urllib3==2.2.2 uvicorn==0.30.1 watchfiles==0.22.0 wcwidth==0.2.13 websocket-client==1.8.0 websockets==12.0 wrapt==1.16.0 yarl==1.9.4 zipp==3.19.2