Need help changing LLM providers for one of the example crews

I am trying to set up and use the marketing strategy crew (crewAI-examples/marketing_strategy at main · crewAIInc/crewAI-examples · GitHub) but I want to use Groq for the inference, not OpenAI.

My .env is updated with my proper keys, I even tried setting up specific calls to it in the python code.

When I run the code it still tells me the OpenAI api key isn’t found, I can’t find anywhere in the code that points to OpenAI, so I assume it’s part of the poetry stuff, but as i’m not a coder and have only been using LLMs to put this stuff together I have no idea what to try next to.

There is this commented section in the ‘def run’ function, is this where I need to put the Groq info? “# Replace with your inputs, it will automatically interpolate any tasks and agents information”

Sorry for what I think is probably a dumb question, Claude and GPT-4o haven’t been helpful in trying to work this out.

2 Likes

Have you made any changes to the example you are using?

Other than the prompt to fit my usecase, and adding my api key for groq instead of openAI, no I haven’t I don’t think (i’m sorry i’m at work and my code is at home lol)

Hi @Wonky!

Thanks for posting.

This is one way you can customize/configure the LLM you’re using; in this case, Groq:

from typing import List
from crewai import Agent, Crew, Process, Task
from crewai.project import CrewBase, agent, crew, task

# Uncomment the following line to use an example of a custom tool
# from marketing_posts.tools.custom_tool import MyCustomTool

# Check our tools documentations for more information on how to use them
from crewai_tools import SerperDevTool, ScrapeWebsiteTool
from pydantic import BaseModel, Field

# Import ChatGroq
from langchain_groq import ChatGroq

... # Keep the code in this section the same

@CrewBase
class MarketingPostsCrew():
	"""MarketingPosts crew"""
	agents_config = 'config/agents.yaml'
	tasks_config = 'config/tasks.yaml'

    def __init__(self):
        # Groq LLM
        self.groq_llm = ChatGroq(
            temperature=0.5,
            groq_api_key=os.environ.get("GROQ_API_KEY"),
            model_name="<MODEL-NAME>",
        )

... # The rest of the code

Make sure you add the API key to the .env file then all you have to do is add the llm=self.groq_llm to each agent.

I hope this helps.

3 Likes

Thank you, im sorry for wasting your time with something so trivial. I have only ever used the ‘crewai create’ functions for my crews in various projects and worked it out with LLMs to get them working. This was the first time trying to use one that was already made.

2 Likes

Hey, no worries. We’re here to help unblock you. Let us know if you run into any other issues.

2 Likes

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