Typo in the utils.py file

Hello there,
Great course!
There is a small, non-impacting issue in the code of the utils.py. While it works great, the choice of words used may cause come confusion to someone trying to follow the code:
In the second function we should change ‘openai_api_key’ to ‘serper_api_key’

def get_openai_api_key():
load_env()
openai_api_key = os.getenv(“OPENAI_API_KEY”)
return openai_api_key

def get_serper_api_key():
load_env()
openai_api_key = os.getenv(“SERPER_API_KEY”)
return openai_api_key

2 Likes

Hi AI_Coder,

If you don’t mind me testing my knowledge with you, is the below fix correct?

def get_openai_api_key():
load_env()
openai_api_key = os.getenv(“OPENAI_API_KEY”)
return openai_api_key

def get_serper_api_key():
load_env()
serper_api_key = os.getenv(“SERPER_API_KEY”)
return serper_api_key
1 Like

100% :slight_smile:

The output remains exactly the same, though.

2 Likes

Yes! Thanks very much. :slight_smile:

1 Like

Thanks all, this has been noted. Good catch!

1 Like

I am taking the class multi AI systems with crewai. I keep getting error message ’ ImportError: cannot import name ‘get_openai_api_key’ from ‘utils’ (/usr/local/lib/python3.10/dist-packages/utils/init.py) - Where does the ‘utils.py’ file come from? Why am I getting the error message - BTW I am using google colab. Thank you very much for your assistance.

1 Like

Hi @caebby,

Firstly, to access your workspace, which has all the files needed in order to run the notebook can be done so by clicking on Menu --> File --> Open... when inside of the Jupyter notebook on the platform. This is where you’ll find the utils.py file, which you can then download.

Secondly, the way it has been set up is that the utils.py file will read the open AI API key from .env file, the visibility of which is not available to the learners, and cannot be used outside of the platform, as it contains our API key. Since you mentioned you are using colab to run the notebook, this won’t work for you as it is.

Now, there are two ways to go about running this using colab:

  1. You can adjust the notebook code or utils.py code that it reads your API directly from the code when running using colab.
  2. You can learn about what .env file is, how to use it using colab and how to populate it by providing your API key by doing a google/chatgpt search. In that case, you should be able to use the code as it is.

Best,
Mubsi

2 Likes

The third option to use in the colab, which is what I did, is to change:

import os
from utils import get_openai_api_key

openai_api_key = get_openai_api_key()
os.environ[“OPENAI_MODEL_NAME”] = ‘gpt-3.5-turbo’

to

import os
os.environ[“OPENAI_MODEL_NAME”] = ‘gpt-3.5-turbo’
os.environ[“OPENAI_API_KEY”] = “your key”

2 Likes