Activity 2 in coding exercise

I get error when I added new review.
NameError Traceback (most recent call last)
Cell In[5], line 12
2 for review in all_reviews:
3 prompt = f’‘’
4 Classify the following review
5 as having either a positive or
(…)
10 {review}
11 ‘’’
—> 12 response = llm_response(prompt)
13 all_sentiments.append(response)
15 all_sentiments

NameError: name ‘llm_response’ is not defined

1 Like

Hi @PreetyGoel

Welcome to the community.

The error is complaining that you are trying to calling a function that wasn’t defined previously

1 Like

Right! The first step in debugging is always to understand what the error message is telling you. Sometimes this can be a bit hard to decipher, but we are lucky that it is quite clear in this instance.

So then the next question is where is that function defined? Probably either by an earlier cell in the notebook or by an “import” command being run in an earlier cell in the notebook. One important point is that you need to run all the previous cells in the notebook every time you open it. So try this:

Cell -> Run All Above

and then try running the failing cell again. The underlying point here is that just having the llm_response code sitting there in a previous cell does nothing: you actually have to execute that cell containing the function or which imports the function in order for the function to actually get created in the “runtime image” of the notebook.

3 Likes

Thank you. I was not running previous codes and directly this one.
If I have to run this command: Cell → Run All Above should I just add this on top?


Run All Above
all_reviews = [
‘The mochi is excellent!’,
‘Best soup dumplings I have ever eaten.’,
‘Not worth the 3 month wait for a reservation.’,
‘The colorful tablecloths made me smile!’,
‘The pasta was cold.’,
‘The manchurian was too dry.’
]

all_reviews

1 Like

No, that’s not how it works. You can’t control the behavior of the notebook by commands in the individual cells. You control the execution by using the menus. This is a UI, right? You are driving it with mouse and keyboard.

2 Likes

Get it. Many Thanks. I am a finance professional . :slight_smile: getting hold of the topic .

1 Like