Candy Analysis in Week 4 Exercise 5

When working on exercise 5 in module 4 my code runs as it is supposed to according to the task directions. yet when I run the

Test your code!, I get the following error:

test_your_code.check_change_in_ex5()
Function get_llm_response not found in the specified cell.

I have gone through a step by step check on this with the AI coach and all seems to be as it should be.

I am referring to this specific task:

"You’ll use the get_llm_response function provided to you below to generate a short, catchy two-sentence description for each of the top candies.

You can adjust the temperature and content variables to fine-tune the responses from the LLM.

Your task:

  • Play around with different temperature settings.
  • Play around with a different content description.

Note In order to get a successful grade for this exercise, you have to set values for other than temperature=0.0 and "content": "You are an AI assistant."

Fun Suggestion: For content, you can use “You talk like a Pirate.” and temperature as 0.5." "

Tip:
When you are working in a notebook, every time you open it, you have to re-run all of the cells starting from the top.

This is where all of the assets are imported and the workspace is created.

Hi @KarlD,

Please do as Tom suggested. If the issue remains, let me know.

Thanks,
Mubsi

Restarted the kernel, and ran through all the steps, and the problem is still there:

Test your code!

test_your_code.check_change_in_ex5()
Function get_llm_response not found in the specified cell.

Hi @KarlD,

I’m going to send you a direct message regarding this.

Hi @KarlD,

Throughout all of the assignments, it has been instructed clearly to only change/write code where you are expected to.

You have changed/modified several code cells in your notebook in ways you were not supposed to. This not only causes issues within the assignment, but will fail the grader as well, because even if you get “All tests passed” message, you implementation is not as expected.

For example:

In exercise 1, you were provided this:

### START CODE HERE ###

# Use 'read_candy_data' to read the file `candy_data.csv`
candy_data = # Add your code here

# Display the contents loaded into the `candy_data` variable
display_table(candy_data) 

### END CODE HERE ###

And this is what you implemented (I’m leaving comments where you wrote solution code):

### START CODE HERE ###

# Import using the format "from file_name import all (*)"
### YOU WROTE YOUR IMPORT STATEMENT HERE AGAIN

# Use the read_candy_data function to read the file candy_data.csv
candy_data = # YOUR SOLUTION CODE

### END CODE HERE ###

Do you see the difference ? You removed the entire display_table function for one.

In exercise 2, you were provided:

### START CODE HERE ###

# Use 'get_popularity_scores' and pass in the lst `candy_data`
popularity_scores = # Add your code here

# Print the `popularity_scores` list
print_scores(popularity_scores) 

### END CODE HERE ###

And this is what you implemented (I’m leaving comments where you wrote solution code):

# Use the get_popularity_scores function with the candy_data
popularity_scores = # YOUR SOLUTION CODE

You again removed the entire print_scores function.

There are several other places where you made changes in the notebook as well, where you were not expected to.

As for your issue of this thread, exercise 5:

This is what you were provided:

### START CODE HERE ###

def get_llm_response(prompt):
    completion = client.chat.completions.create( 
        model='gpt-4o-mini', 
        messages=[ 
            {
                "role": "system",
                "content": "You are an AI assistant.", # <-- You have to make change here
            },
            {"role": "user", "content": prompt},
        ],
        temperature=0.0, # <-- You have to make change here 
    )
    response = completion.choices[0].message.content 
    return response

### END CODE HERE ###

The code clearly mentioned the only two places you were expected to make change. And this is what you implemented:

### START CODE HERE ###

# Import the client from ex5_helper_functions
from ex5_helper_functions import client

# Define the get_llm_response function
def get_llm_response(prompt, temperature=0.7, content="You talk like a connoisseur."):
    completion = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[
            {"role": "system", "content": content},
            {"role": "user", "content": prompt},
        ],
        temperature=temperature,
    )
    response = completion.choices[0].message.content
    return response

# Example usage
top_candies = ["Twix", "M&M's", "Snickers"]
descriptions = []

for candy in top_candies:
    prompt = f"Describe {candy} in a short, catchy two-sentence description."
    description = get_llm_response(prompt)
    descriptions.append(description)

# Print the descriptions
for candy, description in zip(top_candies, descriptions):
    print(f"{candy}: {description}")
    
### END CODE HERE ###

You not only changed the code of the cell, you added additional code, which is why you were getting the error.

Next steps for you:

I have added a fresh copy of the assignment in your workspace C1M4_Assignment.ipynb, please use this file to attempt the assignment again. Follow the instructions and only make changes where you are expected to.

Your previous notebook has been renamed as previous_C1M4_Assignment.ipynb, which can be found in your workspace as well. Do not copy paste solution from here for the reasons I mentioned above. You can use it to reference your previous solutions.

I understand one can be curious to try out different things, play around with the code and all, which you are welcome to do. But do these things after you have received your grade so that it doesn’t cause any inconveniences for you.

Best,
Mubsi

Thank you, I just completed the excercise. As my dad would have said, “Let this be a lesson to you!”

1 Like