In Exercise 1 of the Module 5 assignment, I added a simplified prompt in the graded code area and executed the code, the unit testcase run and the subsequent test fails with UnboundLocalError: cannot access local variable ‘response’ where it is not associated with a value.
I have noticed that this happens primarily for simplified=True function calls.
I tried to manually execute the function check_if_faq_or_product , the no response issue pops up only when simplified is set to True.
Call: check_if_faq_or_product(‘How can I contact the user support?’, False)
Result: (‘FAQ’, 220)
Call: check_if_faq_or_product(‘How can I contact the user support?’, True)
Result:
UnboundLocalError Traceback (most recent call last)
Cell In[33], line 99
96 label = ‘undefined’
98 return label, total_tokens
—> 99 check_if_faq_or_product(‘How can I contact the user support?’, True)
Cell In[33], line 85, in check_if_faq_or_product(query, simplified)
81 router_span.set_status(Status(StatusCode.OK))
84 # Get the Label by accessing the content key of the response dictionary
—> 85 label = response[‘choices’][0][‘message’][‘content’]
86 total_tokens = response[‘usage’][‘total_tokens’]
87 span.set_output(str({“label”: label, ‘total_tokens’:total_tokens}))
UnboundLocalError: cannot access local variable ‘response’ where it is not associated with a value
I wonder if the tracer is broken somehow. Specifically this code’s execution:
with tracer.start_as_current_span("routing_faq_or_product", openinference_span_kind = 'tool') as span:
span.set_input(str({"query":query, "simplified": simplified}))
I tried to skip the 1.4 Optional Telemetry setup to prevent the tracer issues, but realized that’s not possible as tracer is a necessary variable to run 4.1 exercise. So is 1.4 mandatory and not optional, unlike the title says?
Please find the Lab ID and the error messages below.
LAB ID: qrbdmogghssj
Response of Unit Test cases:
Failed test case: check_if_faq_or_product raised an exception with the following parameters query = What are your working hours?.
Expected: check_if_faq_or_product must run without exceptions
Got: cannot access local variable 'response' where it is not associated with a value
Running the following unedited test Let’s test both versions code:
queries = [
‘What is your return policy?’,
‘Give me three examples of blue T-shirts you have available.’,
‘How can I contact the user support?’,
‘Do you have blue Dresses?’,
‘Create a look suitable for a wedding party happening during dawn.’
]
labels = [‘FAQ’, ‘Product’, ‘FAQ’, ‘Product’, ‘Product’]
for query, correct_label in zip(queries, labels):
# Call check_if_faq_or_product and store the results
response_std, tokens_std = check_if_faq_or_product(query, simplified=False)
response_simp, tokens_simp = check_if_faq_or_product(query, simplified=True)
# Print results
process_and_print_query(query, correct_label, response_std, tokens_std, response_simp, tokens_simp)
Result:
UnboundLocalError Traceback (most recent call last)
Cell In[20], line 14
11 for query, correct_label in zip(queries, labels):
12 # Call check_if_faq_or_product and store the results
13 response_std, tokens_std = check_if_faq_or_product(query, simplified=False)
---> 14 response_simp, tokens_simp = check_if_faq_or_product(query, simplified=True)
16 # Print results
17 process_and_print_query(query, correct_label, response_std, tokens_std, response_simp, tokens_simp)
Cell In[18], line 85, in check_if_faq_or_product(query, simplified)
81 router_span.set_status(Status(StatusCode.OK))
84 # Get the Label by accessing the content key of the response dictionary
---> 85 label = response['choices'][0]['message']['content']
86 total_tokens = response['usage']['total_tokens']
87 span.set_output(str({"label": label, 'total_tokens':total_tokens}))
UnboundLocalError: cannot access local variable 'response' where it is not associated with a value