Closed jjsarf closed 7 months ago
I found the answer (albeit I was hoping for a different answer):
The necessity to specify an OpenAI API key in your "Hello World" example using the CrewAI framework, even when the task appears to be simple and not directly related to AI functionalities, might not be intuitively clear. However, the requirement arises from how the CrewAI framework is built and its dependencies, rather than the specific needs of your simple script. Here are the reasons why an OpenAI API key is necessary:
Framework Initialization: CrewAI, being built on top of or alongside OpenAI services, may require an OpenAI API key for initializing the framework itself. This initialization process might involve setting up internal components that rely on OpenAI's services, even if those components are not directly used in the script.
Dependency on OpenAI Services: Even for basic examples, the CrewAI framework might check for the presence of an OpenAI API key to ensure that all its functionalities are available if needed. This check can occur even in scenarios where OpenAI's services are not explicitly invoked by the user's code.
Underlying AI Operations: The CrewAI framework may use AI models or services powered by OpenAI for various operations behind the scenes, including natural language processing tasks, even if those operations are not apparent in the user's script. The API key is necessary to authenticate and authorize these operations.
Design Philosophy: The requirement for an OpenAI API key from the outset can be part of the framework's design philosophy, ensuring that developers have everything set up for broader exploration of the framework's capabilities beyond the basics. This approach facilitates a seamless transition to more complex tasks that require AI functionalities.
Error Handling and Debugging: CrewAI might use OpenAI services for error handling, logging, or debugging purposes. The API key ensures these features are operational, providing a more robust development experience.
In summary, the OpenAI API key requirement in CrewAI, even for simple "Hello World" examples, stems from the framework's integration with OpenAI services and its foundational setup. It ensures that developers can utilize the full range of the framework's capabilities, including those that require access to AI functionalities, without encountering authentication or authorization issues during development.
That is not a hard requirement, docs specify how to use different llms: https://docs.crewai.com/how-to/LLM-Connections/
Okay, but what if you don't want to connect to any?
Get Outlook for Androidhttps://aka.ms/AAb9ysg
From: João Moura @.> Sent: Thursday, March 7, 2024 1:49:41 AM To: joaomdmoura/crewAI @.> Cc: John Jerkovic @.>; State change @.> Subject: Re: [joaomdmoura/crewAI] Hello World needing OpenAI API (Issue #324)
That is not a hard requirement, docs specify how to use different llms: https://docs.crewai.com/how-to/LLM-Connections/
— Reply to this email directly, view it on GitHubhttps://github.com/joaomdmoura/crewAI/issues/324#issuecomment-1982602467, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIFQXASQC7TLRMUHV2VJWMTYXAEYLAVCNFSM6AAAAABEKKBWO6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBSGYYDENBWG4. You are receiving this because you modified the open/close state.Message ID: @.***>
João Moura @joaomdmoura http://twitter.com/joaomdmoura
Em qui., 7 de mar. de 2024 às 03:57, John Jerkovic @.***> escreveu:
Okay, but what if you don't want to connect to any?
Get Outlook for Androidhttps://aka.ms/AAb9ysg
From: João Moura @.> Sent: Thursday, March 7, 2024 1:49:41 AM To: joaomdmoura/crewAI @.> Cc: John Jerkovic @.>; State change @.> Subject: Re: [joaomdmoura/crewAI] Hello World needing OpenAI API (Issue
324)
That is not a hard requirement, docs specify how to use different llms: https://docs.crewai.com/how-to/LLM-Connections/
— Reply to this email directly, view it on GitHub< https://github.com/joaomdmoura/crewAI/issues/324#issuecomment-1982602467>, or unsubscribe< https://github.com/notifications/unsubscribe-auth/AIFQXASQC7TLRMUHV2VJWMTYXAEYLAVCNFSM6AAAAABEKKBWO6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBSGYYDENBWG4>.
You are receiving this because you modified the open/close state.Message ID: @.***>
— Reply to this email directly, view it on GitHub https://github.com/joaomdmoura/crewAI/issues/324#issuecomment-1982626096, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFC3N3PMK4GMAQFLLJNN33YXAFV7AVCNFSM6AAAAABEKKBWO6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBSGYZDMMBZGY . You are receiving this because you commented.Message ID: @.***>
@joaomdmoura Just wondering whether you had a chance to look at this further?
I'm also running into the same issue whereby the code throws an error if the OpenAI API key is not specified, in spite of pointing to Ollama server. And if I provide the OpenAI API key at an environment level and run the code it works, but it is consuming tokens from my OpenAI API account rather than using the Ollama endpoint, even though no part of my code points to OpenAI, other than the environment level API Key.
Basically API's for Ollama, LMStudio, Groq etc. (I have tested on all of those) are not functional without the OpenAI API key and I'm not able to figure out from where the token usage is 'leaking' into my OpenAI account since my code has nothing to that effect.
Please can you help?
I am relatively new to Python and was wondering why would I need OpenAI key for this example which has a custom tool that just prints "Hello World"?
from crewai import Agent, Task, Crew, Process from langchain.tools import tool
Step 1: Define the custom tool
@tool def hello_world_tool(): """This tool prints 'Hello World'.""" return "Hello World"
Step 2: Create an agent with the custom tool
agent = Agent( role='Hello World Printer', goal='Print Hello World', backstory='An agent dedicated to printing Hello World.', tools=[hello_world_tool], verbose=True )
Step 3: Define a task for the agent
task = Task( description='Use the tool to print "Hello World".', agent=agent )
Step 4: Assemble the crew and kickoff
crew = Crew( agents=[agent], tasks=[task], process=Process.sequential, verbose=True )
Execute the task
result = crew.kickoff() print(result)