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
21.62k stars 3k forks source link

[BUG]litellmGemini API not working ? #1393

Open ANPCI opened 1 month ago

ANPCI commented 1 month ago

Description

Crewai generating error when using Gemini pro api, while it's working fine with other openai models.

Steps to Reproduce

add the script to test.py and run it with poetry run python test.py

Expected behavior

it should access gemini api to generate content

Screenshots/Code snippets

import os from langchain_google_genai import ChatGoogleGenerativeAI from crewai import Agent, Task, Crew, Process

if name == "main":

# Set gemini pro as llm
llm = ChatGoogleGenerativeAI(
    model="gemini-pro", verbose=True, temperature=0.9, google_api_key="AIzaSyAfGxWFWyKQk5fzSBKQS4y95JB0Wv_OvYE"
)

# Create agents
screenwriter = Agent(
    role="Screenwriter",
    goal="Translate ideas into engaging scenes with vivid descriptions, snappy dialogue, and emotional depth.",
    backstory="""Former freelance screenwriter for low-budget indie films. Learned to work quickly under constraints, 
                generating multiple variations on a theme. Excels at building tension and incorporating plot twists.""",
    verbose=True,
    allow_delegation=False,
    llm=llm,
)

critic = Agent(
    role="Analytical Eye & Genre Enforcer",
    goal="Ensure stories are internally consistent, adhere to the intended genre, and maintain stylistic choices.",
    backstory="""A retired film studies professor with an encyclopedic knowledge of classic tropes, storytelling structures, 
                and audience expectations. Has a knack for spotting potential plot holes and continuity errors.""",
    verbose=True,
    allow_delegation=False,
    llm=llm,
)

story_master = Agent(
    role="Project Lead & Master Orchestrator",
    goal="Guide the overall story generation process, manage the workflow between the Screenwriter and Critic, and ensure a cohesive final product.",
    backstory="""A seasoned novelist turned game narrative designer. Has a strong understanding of both high-level plot frameworks and the detailed 
                scene creation required to immerse a reader in the world.""",
    verbose=True,
    allow_delegation=True,
    llm=llm,
)

# Get the story idea from the user
user_input = input(
    "Please provide a short story idea. You can specify the genre and theme: "
)

# Create the task
story_task = Task(
    description=f"Write a short story with the following user input: {user_input}",
    agent=story_master,
)

# Create the crew
story_crew = Crew(
    agents=[screenwriter, critic, story_master],
    tasks=[story_task],
    verbose=True,
    process=Process.sequential,
)

# Execution Flow
story_output = story_crew.kickoff()

Operating System

macOS Sonoma

Python Version

3.10

crewAI Version

0.63.6

crewAI Tools Version

0.12.1

Virtual Environment

Poetry

Evidence

Error Message in terminal :

Provider List: https://docs.litellm.ai/docs/providers

2024-10-03 16:03:06,390 - 8480485952 - llm.py-llm:104 - ERROR: Failed to get supported params: argument of type 'NoneType' is not iterable

Possible Solution

None

Additional context

Tried running the script multiple times, same issue

punitchauhan771 commented 1 month ago

Hi

Can you try this?

from crewai import Agent, LLM, Task, Crew, Process
llm = LLM(
model="gemini/gemini-pro", temperature=0.9,
api_key=API_KEY,
)

For reference you can also check this screenshot image

And the rest of your code: image

httplups commented 1 month ago

I also cannot use Gemini with VertexAI in a crew, but it works using the LiteLLM

github-actions[bot] commented 2 weeks ago

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

httplups commented 2 weeks ago

any updates?