Unable to run the code in the jupyter notebook module 2 assignment: C1M2 Assignment

Hi,

I wrote the code and am trying to run it by pressing Shift+Enter. However, after doing so, it neither shows any errors nor displays any results. I’m having trouble understanding the issue-could you please clarify what might be going wrong. I have also done the ML course; it showed an error if there was any, but here there is neither an error nor is the code running. Could you please help me understand why this is happening? And am I doing something wrong? I am getting 0 when i am submitting my code but it is the correct code.

Adding first draft generation code :slight_smile:
GRADED FUNCTION: generate_draft

def generate_draft(topic: str, model: str = “openai:gpt-4o”) → str:

### START CODE HERE ###

# Define your prompt here. A multi-line f-string is typically used for this.
prompt = <Code removed by mentor>




### END CODE HERE ###

# Get a response from the LLM by creating a chat with the client.
response = CLIENT.chat.completions.create(
    model=model,
    messages=[{"role": "user", "content": prompt}],
    temperature=1.0,
)

return response.choices[0].message.content

That cell just defines the prompt. When you “Run” it, it’s compiled, and then it’s ready to be used.

The next cell probably has code that actually runs that prompt.

Nothing is showing up when i run the n ext cell code and when i am submitting the assignment its giving me 0

My other code changes-
GRADED FUNCTION: reflect_on_draft

def reflect_on_draft(draft: str, model: str = “openai:o4-mini”) → str:

### START CODE HERE ###

# Define your prompt here. A multi-line f-string is typically used for this.
prompt = < Code removed by mentor>
### END CODE HERE ###

# Get a response from the LLM by creating a chat with the client.
response = CLIENT.chat.completions.create(
    model=model,
    messages=[{"role": "user", "content": prompt}],
    temperature=1.0
)

return response.choices[0].message.content

GRADED FUNCTION: revise_draft

def revise_draft(original_draft: str, reflection: str, model: str = “openai:gpt-4o”) → str:

### START CODE HERE ###

# Define your prompt here. A multi-line f-string is typically used for this.
prompt = <Code removed by mentor.>

# Get a response from the LLM by creating a chat with the client.
response = < Code removed by mentor>

### END CODE HERE ###

return response.choices[0].message.content

I’m not a mentor for that course, so I don’t have any specific guidance.

@lesly.zerna, do you have some advice for this issue?

@Antara31, I see from another thread that you were able to pass all tests, but that you are still getting a 0 when you submit.

I will delete the code snippets you shared, since it is against community guidelines to share code here, but as far as I can see, your code looks fine.
Some things to try:

1). From the kernel menu, choose Restart and Clear Output

2). Run all the cells in order, making sure you still are passing all the unit tests. Make sure to also run the cells at the end that put it all together and show you the results from all the steps. Make sure these look good, too.

3). From the File menu, choose Save and Checkpoint.

4). Submit your assignment

If you still get 0 on your assignment, please share here a screenshot of the error you are getting for your submission. You can look at the bottom of the assignment to see some screenshots showing you how to open the right panel, where you can see the results from your submissions.

Thank you for reporting! We’ll check what can be happening

cc @a-zarta

Hello - I have a similar issue with Exercise 1 of the module 2 assignment. The code passes the tests but does not generate any output. I tried testing with a Print(response) line but that threw an error that name ‘response’ is not defined. As I understand, response is a variable name that is provided in the exercise. Thank you

Thanks for reporting, let me check with the team!

--
Lesly, DLAI