CrewAI with Cohere

Hi,
I am trying to use crewai with Cohere and not OpenAI. This is for first notebook in the course, with create-agents-to-research-and-write-an-article-(code)

I followed the guideline on your website on how to use Cohere: Connect CrewAI to LLMs - crewAI

I also added llm = ChatCohere() to both research agent as well as writer agent, created tasks and created crew with these 2 agents. No errors till this point.
When I ran the last step,
result = crew.kickoff(inputs={‘topic’: ‘AI in healthcare’})
print(result)

I am getting error:
AuthenticationError: Error code: 401 - {‘error’: {‘message’: ‘Incorrect API key provided: fake. You can find your API key at https://platform.openai.com/account/api-keys.’, ‘type’: ‘invalid_request_error’, ‘param’: None, ‘code’: ‘invalid_api_key’}}

How do I make sure that I can use Cohere LLM for crewAI?
Thanks for your help!

1 Like

Hi @Sachin_Kulkarni3

issue is with incorrect api keys as you are running the codes in your local environment, use OpenAI platform where you need to get your OpenAI API keys.

Regards
DP

Hi Deepti,
I do not want to use OpenAI, and want to use Cohere. I am running code in Colab.
Based on documentation Connect CrewAI to LLMs - crewAI I thought it was possible to use Cohere or other LLMs with CrewAI.
If that is not the case, then I misunderstood what CrewAI could and could not do.
Thanks and Regards,
Sachin

1 Like

Did you try using Cohere api keys??

Also make sure in the utils py file you would require to make changes as per which api key you are using.

Regards
DP

Hi @Sachin_Kulkarni3,

I’m guessing you have taken the code as it is and just replaced the call to openai with cohere ?

Firstly, you need to have a valid cohere API key. Secondly, adjust the code accordingly so that it loads cohere API and not expects an openai API (which is why it is calling it “fake”).

Best,
Mubsi

Hi Mubsi,
It is working now. Thanks for the help. Actually I did not use the code from the DeepLearning Notebook, but used the code from your website- Getting Started:

I found out from other errors that memory=True in Step 3 does not work with Cohere API.
from crewai import Crew, Process

Forming the tech-focused crew with some enhanced configurations

crew = Crew(
agents=[researcher, writer],
tasks=[research_task, write_task],
process=Process.sequential, # Optional: Sequential task execution is default
memory=True,
cache=True,
max_rpm=100,
share_crew=True
)

I made memory=False and then it works.
Actually notebook in this course works correctly with Cohere. No issues, it is just the code on your website does not.
Thanks for the help.
Regards,
Sachin

1 Like

Thanks for sharing the solution @Sachin_Kulkarni3 !

Just a side note, crewai.com is not our website. We are DeepLearning.AI :wink: (crewAI is the partner that collaborated with us on this course)

1 Like