How to change LLM in crewai 0.76.2 whilst using create crew

Hi there. I’m new to CrewAI so I’d really appreciate any help with this.

I created a new project using crewai create crew <project_name> and chose “Gemini” as my provider of choice. The project’s been created and I have a file structure just like the one in the documentation, but by default OpenAI’s GPT4 is the LLM of choice and I’m having a bit of trouble changing that.

I saw some guides about how to change the LLMs for older CrewAI versions where the config was all in one file and you had to define agents manually, but as I understand there is now a switch to using the crewai create crew <project_name> command from now on.

So given this new file structure, where would I change the default LLM from gpt-4o to gemini-1.5.pro? I’ve already specified my gemini api key in the .env file.

Thanks

@ahmadsm1

  1. Use the CrewAI LLM class, which leverages LiteLLM in the background.
  2. Make sure to set the LLM provider before configuring the LLM. For Anthropic, use anthropic/<LLM name>. If you’re unsure how to do this for a specific LLM provider, refer to the LiteLLM Providers page for guidance.

Also, see the docs.

from crewai import Agent, LLM

my_llm = LLM(
    api_key=os.getenv("ANTHROPIC_API_KEY"),
    model="anthropic/claude-3-5-sonnet-20240620",
),

my_agent = Agent(
    ...,
    llm=my_llm,
)
3 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.