Print_llm_response from helper_functions works in Jupyter notebook but not in VS Code

Hi everyone,

I am currently taking the AI Python for Beginners course from DeepLearning.AI.

In the course notebook, the following import works correctly:

from helper_functions import print_llm_response

and the code runs successfully inside the Jupyter notebook environment provided by the course.

However, when I try to run the same code in Visual Studio Code on my desktop, it does not work.

I suspect that “helper_functions.py” may be part of the course environment and is not available locally on my machine.

Has anyone experienced this before?

I would appreciate help on:

- How to locate or install “helper_functions.py”

- How to make the code work in VS Code

- Whether this function is only available inside the course notebook environment

- Best practice for running these course examples locally

Thank you in advance for your help!

Hi Peiting_Lin,

From the course notebook go to File → Open

This takes you to the course folder where you can find helper_functions.py. You can then select and download it so that you can use it on your local machine.

Where can I find the course notebook? I couldn’t find it—could this be due to my free subscription plan?

Hi Peiting_Lin,

If you go to ‘Building LLM prompts with variables’, the notebook you mentioned opens. From there you can go to File → Open and find helper_functions.py.

Using it locally is not a trivial task, as mentioned by @TMosh. First, you would have to set up a virtual environment and perform (potentially) required package installs. Then you would need to place helper_functions.py in this virtual environment together with the file from which you run your code. To run the code successfully you would also have to set up your openai_api_key and use it in the line in helper_functions.py that uses the key (client = OpenAI(api_key=openai_api_key)). See https://help.openai.com/en/articles/4936850-where-do-i-find-my-openai-api-key.

If you are just starting your learning journey, it may be advisable to postpone this for now. Whichever you choose to do, good luck and happy learning!

If you do not have a Pro subscription, you cannot access the graded assignments.

Does this mean I should learn and master basic Python first, and then continue with this course?

No, that is not necessary. There are two ways in which you can look at this.

If you continue with the course, accepting that you cannot (yet) reproduce the exact flow on your own device, you will learn how chatbots can be used together with python conceptually and you will get programming experience in doing so. You can then later decide whether or not you want to dive into the process of setting up a virtual environment, doing package installs, setting up your local chatbot key, and organizing your files correctly.

Alternatively, you could look into how to work with a virtual environment ( Python Virtual Environment - venv ), and how to work with a local chatbot key. That is not so much about learning python, but rather about system administration / devops. It is not as difficult as it may seem, but it will require trial and error and persistence.

So just enjoy the course, and see if you want to dive into the world of system administration / devops. It is nice to know how to run everything locally, but it does require persistence.

Hi @Peiting_Lin,

As Reinoud mentioned, it’s best to wait till you learn a bit.

But the good news is, you don’t have to wait for long! In the last module of this course, this all will be covered, so I’d suggest to wait till then.

Best,
Mubsi