CrewAi: installation issue and error on from utils import get_openai_api_key

Inspite of installing utils when performing the following import

from utils import get_openai_api_key
openai_api_key = get_openai_api_key()

os.environ[“OPENAI_MODEL_NAME”] = ‘gpt-3.5-turbo’
I get the following error
ImportError: cannot import name ‘get_openai_api_key’ from ‘utils’ (/usr/local/lib/python3.11/dist-packages/utils/init.py)

What am I missing in my import?

Please post your message in the forum area for that course.

The “AI Discussions” forum is for general topics - not specific courses.

Assuming for instance you are refering to the L2_research_write_article notebook - where you actually can find your snippet code - two considerations that perphaps might help you;

  • Have you properly upload the utils.py file and enclosed this in the same directory of your notebook and .env file?

  • Have you set up correctly your OPENAI_API_KEY in the .env file?

Hi,

Could you kindly show where would one find the:

“OPENAI_API_KEY in the .env file”?

If you run locally, you should create an .env file in which you enclose the value of OPENAI_API_KEY

# OpenAI API Key
OPENAI_API_KEY=YOUR_OPENAI_API_KEY_HERE

PS: To use your open api key you should pay. Therefore, I would suggest you to use the Hugging Face model (see for instance advice at the end of notebook L2 research write article) and further enclose in the .env file your HF_TOKEN that is free.

# HuggingFace API key 
HF_API_KEY=YOUR_HUGGINGFACE_API_TOKEN_HERE

Happy coding!

1 Like