Here’s an example of the product that the above generate_output_string() function pulled out. This product is neither in the products nor in the categories mentioned in the user query. However, information on its features says it is compatible with another product (SmartX ProPhone). The SmartX ProPhone is mentioned in the user query.
{
“name”: “MobiTech PowerCase”,
“category”: “Smartphones and Accessories”,
“brand”: “MobiTech”,
“model_number”: “MT-PC20”,
“warranty”: “1 year”,
“rating”: 4.3,
“features”: [
“5000mAh battery”,
“Wireless charging”,
“Compatible with SmartX ProPhone”
],
“description”: “A protective case with built-in battery for extended usage.”,
“price”: 59.99
}
It seems that there is an error in the system_message in the course notebook. The relevant part of the system_message should be MODIFIED as follows:
system_message = f"“”
You will be provided with customer service queries.
The customer service query will be delimited with
{delimiter} characters.
Output a python list of objects, where each object has
the following format:
‘category’: <one of Computers and Laptops,
Smartphones and Accessories,
Televisions and Home Theater Systems,
Gaming Consoles and Accessories,
Audio Equipment, Cameras and Camcorders>,
OR/AND
‘products’: <a list of products that must
be found in the allowed products below>
<rest of the **system_message**>
NOTE: The only MODIFICATION I made is to replace “OR” in the original system_message with “OR/AND”.
If you make the above change then: print(category_and_product_response_1) will produce the following output:
[
{‘category’: ‘Smartphones and Accessories’, ‘products’: [‘SmartX ProPhone’]},
{‘category’: ‘Cameras and Camcorders’, ‘products’: [‘FotoSnap DSLR Camera’]},
{‘category’: ‘Televisions and Home Theater Systems’}
]
Then everything else will fall into place.
The generate_output_string() function will produce dictionaries for only those products that were mentioned in the user query. No unrelated product dictionary will be extracted.
When the user does not mention a specific product but only mentions a category (e.g., TVs), then product details dictionaries for all products in that category will be extracted and printed. This is what it should do.