Finish Systems

This commit is contained in:
nowadays0421
2023-07-23 20:14:15 +08:00
parent 599a1b4126
commit 81097456f5
7 changed files with 3559 additions and 0 deletions

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,20 @@
{"计费":
["取消订阅或升级",
"添加付款方式",
"收费解释",
"争议费用"],
"技术支持":
["常规故障排除",
"设备兼容性",
"软件更新"],
"账户管理":
["重置密码",
"更新个人信息",
"关闭账户",
"账户安全"],
"一般咨询":
["产品信息",
"定价",
"反馈",
"与人工对话"]
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,336 @@
{
"TechPro Ultrabook": {
"名称": "TechPro 超极本",
"类别": "电脑和笔记本",
"品牌": "TechPro",
"型号": "TP-UB100",
"保修期": "1 year",
"评分": 4.5,
"特色": ["13.3-inch display", "8GB RAM", "256GB SSD", "Intel Core i5 处理器"],
"描述": "一款时尚轻便的超极本,适合日常使用。",
"价格": 799.99
},
"BlueWave Gaming Laptop": {
"名称": "BlueWave 游戏本",
"类别": "电脑和笔记本",
"品牌": "BlueWave",
"型号": "BW-GL200",
"保修期": "2 years",
"评分": 4.7,
"特色": ["15.6-inch display", "16GB RAM", "512GB SSD", "NVIDIA GeForce RTX 3060"],
"描述": "一款高性能的游戏笔记本电脑,提供沉浸式体验。",
"价格": 1199.99
},
"PowerLite Convertible": {
"名称": "PowerLite Convertible",
"类别": "电脑和笔记本",
"品牌": "PowerLite",
"型号": "PL-CV300",
"保修期": "1 year",
"评分": 4.3,
"特色": ["14-inch touchscreen", "8GB RAM", "256GB SSD", "360-degree hinge"],
"描述": "一款多功能的可转换笔记本电脑,具有灵敏的触摸屏。",
"价格": 699.99
},
"TechPro Desktop": {
"名称": "TechPro Desktop",
"类别": "电脑和笔记本",
"品牌": "TechPro",
"型号": "TP-DT500",
"保修期": "1 year",
"评分": 4.4,
"特色": ["Intel Core i7 processor", "16GB RAM", "1TB HDD", "NVIDIA GeForce GTX 1660"],
"描述": "一款功能强大的台式电脑,适用于工作和娱乐。",
"价格": 999.99
},
"BlueWave Chromebook": {
"名称": "BlueWave Chromebook",
"类别": "电脑和笔记本",
"品牌": "BlueWave",
"型号": "BW-CB100",
"保修期": "1 year",
"评分": 4.1,
"特色": ["11.6-inch display", "4GB RAM", "32GB eMMC", "Chrome OS"],
"描述": "一款紧凑而价格实惠的Chromebook适用于日常任务。",
"价格": 249.99
},
"SmartX ProPhone": {
"名称": "SmartX ProPhone",
"类别": "智能手机和配件",
"品牌": "SmartX",
"型号": "SX-PP10",
"保修期": "1 year",
"评分": 4.6,
"特色": ["6.1-inch display", "128GB storage", "12MP dual camera", "5G"],
"描述": "一款拥有先进摄像功能的强大智能手机。",
"价格": 899.99
},
"MobiTech PowerCase": {
"名称": "MobiTech PowerCase",
"类别": "智能手机和配件",
"品牌": "MobiTech",
"型号": "MT-PC20",
"保修期": "1 year",
"评分": 4.3,
"特色": ["5000mAh battery", "Wireless charging", "Compatible with SmartX ProPhone"],
"描述": "一款带有内置电池的保护手机壳,可延长使用时间。",
"价格": 59.99
},
"SmartX MiniPhone": {
"名称": "SmartX MiniPhone",
"类别": "智能手机和配件",
"品牌": "SmartX",
"型号": "SX-MP5",
"保修期": "1 year",
"评分": 4.2,
"特色": ["4.7-inch display", "64GB storage", "8MP camera", "4G"],
"描述": "一款紧凑而价格实惠的智能手机,适用于基本任务。",
"价格": 399.99
},
"MobiTech Wireless Charger": {
"名称": "MobiTech Wireless Charger",
"类别": "智能手机和配件",
"品牌": "MobiTech",
"型号": "MT-WC10",
"保修期": "1 year",
"评分": 4.5,
"特色": ["10W fast charging", "Qi-compatible", "LED indicator", "Compact design"],
"描述": "一款方便的无线充电器,使工作区域整洁无杂物。",
"价格": 29.99
},
"SmartX EarBuds": {
"名称": "SmartX EarBuds",
"类别": "智能手机和配件",
"品牌": "SmartX",
"型号": "SX-EB20",
"保修期": "1 year",
"评分": 4.4,
"特色": ["True wireless", "Bluetooth 5.0", "Touch controls", "24-hour battery life"],
"描述": "通过这些舒适的耳塞体验真正的无线自由。",
"价格": 99.99
},
"CineView 4K TV": {
"名称": "CineView 4K TV",
"类别": "电视和家庭影院系统",
"品牌": "CineView",
"型号": "CV-4K55",
"保修期": "2 years",
"评分": 4.8,
"特色": ["55-inch display", "4K resolution", "HDR", "Smart TV"],
"描述": "一款色彩鲜艳、智能功能丰富的惊艳4K电视。",
"价格": 599.99
},
"SoundMax Home Theater": {
"名称": "SoundMax Home Theater",
"类别": "电视和家庭影院系统",
"品牌": "SoundMax",
"型号": "SM-HT100",
"保修期": "1 year",
"评分": 4.4,
"特色": ["5.1 channel", "1000W output", "Wireless subwoofer", "Bluetooth"],
"描述": "一款强大的家庭影院系统,提供沉浸式音频体验。",
"价格": 399.99
},
"CineView 8K TV": {
"名称": "CineView 8K TV",
"类别": "电视和家庭影院系统",
"品牌": "CineView",
"型号": "CV-8K65",
"保修期": "2 years",
"评分": 4.9,
"特色": ["65-inch display", "8K resolution", "HDR", "Smart TV"],
"描述": "通过这款惊艳的8K电视体验未来。",
"价格": 2999.99
},
"SoundMax Soundbar": {
"名称": "SoundMax Soundbar",
"类别": "电视和家庭影院系统",
"品牌": "SoundMax",
"型号": "SM-SB50",
"保修期": "1 year",
"评分": 4.3,
"特色": ["2.1 channel", "300W output", "Wireless subwoofer", "Bluetooth"],
"描述": "使用这款时尚而功能强大的声音,升级您电视的音频体验。",
"价格": 199.99
},
"CineView OLED TV": {
"名称": "CineView OLED TV",
"类别": "电视和家庭影院系统",
"品牌": "CineView",
"型号": "CV-OLED55",
"保修期": "2 years",
"评分": 4.7,
"特色": ["55-inch display", "4K resolution", "HDR", "Smart TV"],
"描述": "通过这款OLED电视体验真正的五彩斑斓。",
"价格": 1499.99
},
"GameSphere X": {
"名称": "GameSphere X",
"类别": "游戏机和配件",
"品牌": "GameSphere",
"型号": "GS-X",
"保修期": "1 year",
"评分": 4.9,
"特色": ["4K gaming", "1TB storage", "Backward compatibility", "Online multiplayer"],
"描述": "一款下一代游戏机,提供终极游戏体验。",
"价格": 499.99
},
"ProGamer Controller": {
"名称": "ProGamer Controller",
"类别": "游戏机和配件",
"品牌": "ProGamer",
"型号": "PG-C100",
"保修期": "1 year",
"评分": 4.2,
"特色": ["Ergonomic design", "Customizable buttons", "Wireless", "Rechargeable battery"],
"描述": "一款高品质的游戏手柄,提供精准和舒适的操作。",
"价格": 59.99
},
"GameSphere Y": {
"名称": "GameSphere Y",
"类别": "游戏机和配件",
"品牌": "GameSphere",
"型号": "GS-Y",
"保修期": "1 year",
"评分": 4.8,
"特色": ["4K gaming", "500GB storage", "Backward compatibility", "Online multiplayer"],
"描述": "一款体积紧凑、性能强劲的游戏机。",
"价格": 399.99
},
"ProGamer Racing Wheel": {
"名称": "ProGamer Racing Wheel",
"类别": "游戏机和配件",
"品牌": "ProGamer",
"型号": "PG-RW200",
"保修期": "1 year",
"评分": 4.5,
"特色": ["Force feedback", "Adjustable pedals", "Paddle shifters", "Compatible with GameSphere X"],
"描述": "使用这款逼真的赛车方向盘,提升您的赛车游戏体验。",
"价格": 249.99
},
"GameSphere VR Headset": {
"名称": "GameSphere VR Headset",
"类别": "游戏机和配件",
"品牌": "GameSphere",
"型号": "GS-VR",
"保修期": "1 year",
"评分": 4.6,
"特色": ["Immersive VR experience", "Built-in headphones", "Adjustable headband", "Compatible with GameSphere X"],
"描述": "通过这款舒适的VR头戴设备进入虚拟现实的世界。",
"价格": 299.99
},
"AudioPhonic Noise-Canceling Headphones": {
"名称": "AudioPhonic Noise-Canceling Headphones",
"类别": "音频设备",
"品牌": "AudioPhonic",
"型号": "AP-NC100",
"保修期": "1 year",
"评分": 4.6,
"特色": ["Active noise-canceling", "Bluetooth", "20-hour battery life", "Comfortable fit"],
"描述": "通过这款降噪耳机,体验沉浸式的音效。",
"价格": 199.99
},
"WaveSound Bluetooth Speaker": {
"名称": "WaveSound Bluetooth Speaker",
"类别": "音频设备",
"品牌": "WaveSound",
"型号": "WS-BS50",
"保修期": "1 year",
"评分": 4.5,
"特色": ["Portable", "10-hour battery life", "Water-resistant", "Built-in microphone"],
"描述": "一款紧凑而多用途的蓝牙音箱,适用于随时随地收听音乐。",
"价格": 49.99
},
"AudioPhonic True Wireless Earbuds": {
"名称": "AudioPhonic True Wireless Earbuds",
"类别": "音频设备",
"品牌": "AudioPhonic",
"型号": "AP-TW20",
"保修期": "1 year",
"评分": 4.4,
"特色": ["True wireless", "Bluetooth 5.0", "Touch controls", "18-hour battery life"],
"描述": "通过这款舒适的真无线耳塞,无需线缆即可享受音乐。",
"价格": 79.99
},
"WaveSound Soundbar": {
"名称": "WaveSound Soundbar",
"类别": "音频设备",
"品牌": "WaveSound",
"型号": "WS-SB40",
"保修期": "1 year",
"评分": 4.3,
"特色": ["2.0 channel", "80W output", "Bluetooth", "Wall-mountable"],
"描述": "使用这款纤薄而功能强大的声音吧,升级您电视的音频体验。",
"价格": 99.99
},
"AudioPhonic Turntable": {
"名称": "AudioPhonic Turntable",
"类别": "音频设备",
"品牌": "AudioPhonic",
"型号": "AP-TT10",
"保修期": "1 year",
"评分": 4.2,
"特色": ["3-speed", "Built-in speakers", "Bluetooth", "USB recording"],
"描述": "通过这款现代化的唱片机,重拾您的黑胶唱片收藏。",
"价格": 149.99
},
"FotoSnap DSLR Camera": {
"名称": "FotoSnap DSLR Camera",
"类别": "相机和摄像机",
"品牌": "FotoSnap",
"型号": "FS-DSLR200",
"保修期": "1 year",
"评分": 4.7,
"特色": ["24.2MP sensor", "1080p video", "3-inch LCD", "Interchangeable lenses"],
"描述": "使用这款多功能的单反相机,捕捉惊艳的照片和视频。",
"价格": 599.99
},
"ActionCam 4K": {
"名称": "ActionCam 4K",
"类别": "相机和摄像机",
"品牌": "ActionCam",
"型号": "AC-4K",
"保修期": "1 year",
"评分": 4.4,
"特色": ["4K video", "Waterproof", "Image stabilization", "Wi-Fi"],
"描述": "使用这款坚固而紧凑的4K运动相机记录您的冒险旅程。",
"价格": 299.99
},
"FotoSnap Mirrorless Camera": {
"名称": "FotoSnap Mirrorless Camera",
"类别": "相机和摄像机",
"品牌": "FotoSnap",
"型号": "FS-ML100",
"保修期": "1 year",
"评分": 4.6,
"特色": ["20.1MP sensor", "4K video", "3-inch touchscreen", "Interchangeable lenses"],
"描述": "一款具有先进功能的小巧轻便的无反相机。",
"价格": 799.99
},
"ZoomMaster Camcorder": {
"名称": "ZoomMaster Camcorder",
"类别": "相机和摄像机",
"品牌": "ZoomMaster",
"型号": "ZM-CM50",
"保修期": "1 year",
"评分": 4.3,
"特色": ["1080p video", "30x optical zoom", "3-inch LCD", "Image stabilization"],
"描述": "使用这款易于使用的摄像机,捕捉生活的瞬间。",
"价格": 249.99
},
"FotoSnap Instant Camera": {
"名称": "FotoSnap Instant Camera",
"类别": "相机和摄像机",
"品牌": "FotoSnap",
"型号": "FS-IC10",
"保修期": "1 year",
"评分": 4.1,
"特色": ["Instant prints", "Built-in flash", "Selfie mirror", "Battery-powered"],
"描述": "使用这款有趣且便携的即时相机,创造瞬间回忆。",
"价格": 69.99
}
}

View File

@ -0,0 +1,778 @@
import json
import openai
from collections import defaultdict
# 商品和目录的数据文件
products_file = 'products.json'
categories_file = 'categories.json'
# 分隔符
delimiter = "####"
# 第二步(抽取商品)系统信息文本
step_2_system_message_content = f"""
You will be provided with customer service a conversation. \
The most recent user 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
'products': <a list of products that must \
be found in the allowed products below>
Where the categories and products must be found in \
the customer service query.
If a product is mentioned, it must be associated with \
the correct category in the allowed products list below.
If no products or categories are found, output an \
empty list.
Only list products and categories that have not already \
been mentioned and discussed in the earlier parts of \
the conversation.
Allowed products:
Computers and Laptops category:
TechPro Ultrabook
BlueWave Gaming Laptop
PowerLite Convertible
TechPro Desktop
BlueWave Chromebook
Smartphones and Accessories category:
SmartX ProPhone
MobiTech PowerCase
SmartX MiniPhone
MobiTech Wireless Charger
SmartX EarBuds
Televisions and Home Theater Systems category:
CineView 4K TV
SoundMax Home Theater
CineView 8K TV
SoundMax Soundbar
CineView OLED TV
Gaming Consoles and Accessories category:
GameSphere X
ProGamer Controller
GameSphere Y
ProGamer Racing Wheel
GameSphere VR Headset
Audio Equipment category:
AudioPhonic Noise-Canceling Headphones
WaveSound Bluetooth Speaker
AudioPhonic True Wireless Earbuds
WaveSound Soundbar
AudioPhonic Turntable
Cameras and Camcorders category:
FotoSnap DSLR Camera
ActionCam 4K
FotoSnap Mirrorless Camera
ZoomMaster Camcorder
FotoSnap Instant Camera
Only output the list of objects, with nothing else.
"""
step_2_system_message = {'role':'system', 'content': step_2_system_message_content}
# 第四步(生成用户回答)的系统信息
step_4_system_message_content = f"""
You are a customer service assistant for a large electronic store. \
Respond in a friendly and helpful tone, with VERY concise answers. \
Make sure to ask the user relevant follow-up questions.
"""
step_4_system_message = {'role':'system', 'content': step_4_system_message_content}
# 第六步(验证模型回答)的系统信息
step_6_system_message_content = f"""
You are an assistant that evaluates whether \
customer service agent responses sufficiently \
answer customer questions, and also validates that \
all the facts the assistant cites from the product \
information are correct.
The conversation history, product information, user and customer \
service agent messages will be delimited by \
3 backticks, i.e. ```.
Respond with a Y or N character, with no punctuation:
Y - if the output sufficiently answers the question \
AND the response correctly uses product information
N - otherwise
Output a single letter only.
"""
step_6_system_message = {'role':'system', 'content': step_6_system_message_content}
# 使用 ChatCompletion 接口
def get_completion_from_messages(messages, model="gpt-3.5-turbo", temperature=0, max_tokens=500):
response = openai.ChatCompletion.create(
model=model,
messages=messages,
temperature=temperature,
max_tokens=max_tokens,
)
return response.choices[0].message["content"]
# 创建目录(如果没有本地目录文件,需要创建一份)
def create_categories():
categories_dict = {
'Billing': [
'Unsubscribe or upgrade',
'Add a payment method',
'Explanation for charge',
'Dispute a charge'],
'Technical Support':[
'General troubleshooting'
'Device compatibility',
'Software updates'],
'Account Management':[
'Password reset'
'Update personal information',
'Close account',
'Account security'],
'General Inquiry':[
'Product information'
'Pricing',
'Feedback',
'Speak to a human']
}
with open(categories_file, 'w') as file:
json.dump(categories_dict, file)
return categories_dict
# 获取目录数据
def get_categories():
with open(categories_file, 'r') as file:
categories = json.load(file)
return categories
# 获取商品列表
def get_product_list():
"""
具体原理参见第四节课
"""
products = get_products()
product_list = []
for product in products.keys():
product_list.append(product)
return product_list
# 获取商品和目录
def get_products_and_category():
"""
具体原理参见第五节课
"""
products = get_products()
products_by_category = defaultdict(list)
for product_name, product_info in products.items():
category = product_info.get('category')
if category:
products_by_category[category].append(product_info.get('name'))
return dict(products_by_category)
# 从商品数据中获取
def get_products():
with open(products_file, 'r') as file:
products = json.load(file)
return products
# 从用户问题中抽取商品和类别
def find_category_and_product(user_input,products_and_category):
delimiter = "####"
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 json 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
'products': <a list of products that must be found in the allowed products below>
Where the categories and products must be found in the customer service query.
If a product is mentioned, it must be associated with the correct category in the allowed products list below.
If no products or categories are found, output an empty list.
The allowed products are provided in JSON format.
The keys of each item represent the category.
The values of each item is a list of products that are within that category.
Allowed products: {products_and_category}
"""
messages = [
{'role':'system', 'content': system_message},
{'role':'user', 'content': f"{delimiter}{user_input}{delimiter}"},
]
return get_completion_from_messages(messages)
# 相比上一个函数,限制了可获取的商品
def find_category_and_product_only(user_input,products_and_category):
delimiter = "####"
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
'products': <a list of products that must be found in the allowed products below>
Where the categories and products must be found in the customer service query.
If a product is mentioned, it must be associated with the correct category in the allowed products list below.
If no products or categories are found, output an empty list.
Allowed products:
Computers and Laptops category:
TechPro Ultrabook
BlueWave Gaming Laptop
PowerLite Convertible
TechPro Desktop
BlueWave Chromebook
Smartphones and Accessories category:
SmartX ProPhone
MobiTech PowerCase
SmartX MiniPhone
MobiTech Wireless Charger
SmartX EarBuds
Televisions and Home Theater Systems category:
CineView 4K TV
SoundMax Home Theater
CineView 8K TV
SoundMax Soundbar
CineView OLED TV
Gaming Consoles and Accessories category:
GameSphere X
ProGamer Controller
GameSphere Y
ProGamer Racing Wheel
GameSphere VR Headset
Audio Equipment category:
AudioPhonic Noise-Canceling Headphones
WaveSound Bluetooth Speaker
AudioPhonic True Wireless Earbuds
WaveSound Soundbar
AudioPhonic Turntable
Cameras and Camcorders category:
FotoSnap DSLR Camera
ActionCam 4K
FotoSnap Mirrorless Camera
ZoomMaster Camcorder
FotoSnap Instant Camera
Only output the list of objects, nothing else.
"""
messages = [
{'role':'system', 'content': system_message},
{'role':'user', 'content': f"{delimiter}{user_input}{delimiter}"},
]
return get_completion_from_messages(messages)
# 从问题中抽取商品
def get_products_from_query(user_msg):
"""
代码来自于第五节课
"""
products_and_category = get_products_and_category()
delimiter = "####"
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 json 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
'products': <a list of products that must be found in the allowed products below>
Where the categories and products must be found in the customer service query.
If a product is mentioned, it must be associated with the correct category in the allowed products list below.
If no products or categories are found, output an empty list.
The allowed products are provided in JSON format.
The keys of each item represent the category.
The values of each item is a list of products that are within that category.
Allowed products: {products_and_category}
"""
messages = [
{'role':'system', 'content': system_message},
{'role':'user', 'content': f"{delimiter}{user_msg}{delimiter}"},
]
category_and_product_response = get_completion_from_messages(messages)
return category_and_product_response
# 商品信息的搜索
def get_product_by_name(name):
products = get_products()
return products.get(name, None)
def get_products_by_category(category):
products = get_products()
return [product for product in products.values() if product["category"] == category]
def get_mentioned_product_info(data_list):
"""
具体原理参见第五、六节课
"""
product_info_l = []
if data_list is None:
return product_info_l
for data in data_list:
try:
if "products" in data:
products_list = data["products"]
for product_name in products_list:
product = get_product_by_name(product_name)
if product:
product_info_l.append(product)
else:
print(f"Error: Product '{product_name}' not found")
elif "category" in data:
category_name = data["category"]
category_products = get_products_by_category(category_name)
for product in category_products:
product_info_l.append(product)
else:
print("Error: Invalid object format")
except Exception as e:
print(f"Error: {e}")
return product_info_l
# 以下函数原理参见第五节课
def read_string_to_list(input_string):
if input_string is None:
return None
try:
input_string = input_string.replace("'", "\"") # Replace single quotes with double quotes for valid JSON
data = json.loads(input_string)
return data
except json.JSONDecodeError:
print("Error: Invalid JSON string")
return None
def generate_output_string(data_list):
output_string = ""
if data_list is None:
return output_string
for data in data_list:
try:
if "products" in data:
products_list = data["products"]
for product_name in products_list:
product = get_product_by_name(product_name)
if product:
output_string += json.dumps(product, indent=4) + "\n"
else:
print(f"Error: Product '{product_name}' not found")
elif "category" in data:
category_name = data["category"]
category_products = get_products_by_category(category_name)
for product in category_products:
output_string += json.dumps(product, indent=4) + "\n"
else:
print("Error: Invalid object format")
except Exception as e:
print(f"Error: {e}")
return output_string
# Example usage:
#product_information_for_user_message_1 = generate_output_string(category_and_product_list)
#print(product_information_for_user_message_1)
# 回答用户问题
def answer_user_msg(user_msg,product_info):
"""
代码参见第五节课
"""
delimiter = "####"
system_message = f"""
You are a customer service assistant for a large electronic store. \
Respond in a friendly and helpful tone, with concise answers. \
Make sure to ask the user relevant follow up questions.
"""
# user_msg = f"""
# tell me about the smartx pro phone and the fotosnap camera, the dslr one. Also what tell me about your tvs"""
messages = [
{'role':'system', 'content': system_message},
{'role':'user', 'content': f"{delimiter}{user_msg}{delimiter}"},
{'role':'assistant', 'content': f"Relevant product information:\n{product_info}"},
]
response = get_completion_from_messages(messages)
return response
# 创建并存入商品数据
def create_products():
"""
Create products dictionary and save it to a file named products.json
"""
# product information
# fun fact: all these products are fake and were generated by a language model
products = {
"TechPro Ultrabook": {
"name": "TechPro Ultrabook",
"category": "Computers and Laptops",
"brand": "TechPro",
"model_number": "TP-UB100",
"warranty": "1 year",
"rating": 4.5,
"features": ["13.3-inch display", "8GB RAM", "256GB SSD", "Intel Core i5 processor"],
"description": "A sleek and lightweight ultrabook for everyday use.",
"price": 799.99
},
"BlueWave Gaming Laptop": {
"name": "BlueWave Gaming Laptop",
"category": "Computers and Laptops",
"brand": "BlueWave",
"model_number": "BW-GL200",
"warranty": "2 years",
"rating": 4.7,
"features": ["15.6-inch display", "16GB RAM", "512GB SSD", "NVIDIA GeForce RTX 3060"],
"description": "A high-performance gaming laptop for an immersive experience.",
"price": 1199.99
},
"PowerLite Convertible": {
"name": "PowerLite Convertible",
"category": "Computers and Laptops",
"brand": "PowerLite",
"model_number": "PL-CV300",
"warranty": "1 year",
"rating": 4.3,
"features": ["14-inch touchscreen", "8GB RAM", "256GB SSD", "360-degree hinge"],
"description": "A versatile convertible laptop with a responsive touchscreen.",
"price": 699.99
},
"TechPro Desktop": {
"name": "TechPro Desktop",
"category": "Computers and Laptops",
"brand": "TechPro",
"model_number": "TP-DT500",
"warranty": "1 year",
"rating": 4.4,
"features": ["Intel Core i7 processor", "16GB RAM", "1TB HDD", "NVIDIA GeForce GTX 1660"],
"description": "A powerful desktop computer for work and play.",
"price": 999.99
},
"BlueWave Chromebook": {
"name": "BlueWave Chromebook",
"category": "Computers and Laptops",
"brand": "BlueWave",
"model_number": "BW-CB100",
"warranty": "1 year",
"rating": 4.1,
"features": ["11.6-inch display", "4GB RAM", "32GB eMMC", "Chrome OS"],
"description": "A compact and affordable Chromebook for everyday tasks.",
"price": 249.99
},
"SmartX ProPhone": {
"name": "SmartX ProPhone",
"category": "Smartphones and Accessories",
"brand": "SmartX",
"model_number": "SX-PP10",
"warranty": "1 year",
"rating": 4.6,
"features": ["6.1-inch display", "128GB storage", "12MP dual camera", "5G"],
"description": "A powerful smartphone with advanced camera features.",
"price": 899.99
},
"MobiTech PowerCase": {
"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
},
"SmartX MiniPhone": {
"name": "SmartX MiniPhone",
"category": "Smartphones and Accessories",
"brand": "SmartX",
"model_number": "SX-MP5",
"warranty": "1 year",
"rating": 4.2,
"features": ["4.7-inch display", "64GB storage", "8MP camera", "4G"],
"description": "A compact and affordable smartphone for basic tasks.",
"price": 399.99
},
"MobiTech Wireless Charger": {
"name": "MobiTech Wireless Charger",
"category": "Smartphones and Accessories",
"brand": "MobiTech",
"model_number": "MT-WC10",
"warranty": "1 year",
"rating": 4.5,
"features": ["10W fast charging", "Qi-compatible", "LED indicator", "Compact design"],
"description": "A convenient wireless charger for a clutter-free workspace.",
"price": 29.99
},
"SmartX EarBuds": {
"name": "SmartX EarBuds",
"category": "Smartphones and Accessories",
"brand": "SmartX",
"model_number": "SX-EB20",
"warranty": "1 year",
"rating": 4.4,
"features": ["True wireless", "Bluetooth 5.0", "Touch controls", "24-hour battery life"],
"description": "Experience true wireless freedom with these comfortable earbuds.",
"price": 99.99
},
"CineView 4K TV": {
"name": "CineView 4K TV",
"category": "Televisions and Home Theater Systems",
"brand": "CineView",
"model_number": "CV-4K55",
"warranty": "2 years",
"rating": 4.8,
"features": ["55-inch display", "4K resolution", "HDR", "Smart TV"],
"description": "A stunning 4K TV with vibrant colors and smart features.",
"price": 599.99
},
"SoundMax Home Theater": {
"name": "SoundMax Home Theater",
"category": "Televisions and Home Theater Systems",
"brand": "SoundMax",
"model_number": "SM-HT100",
"warranty": "1 year",
"rating": 4.4,
"features": ["5.1 channel", "1000W output", "Wireless subwoofer", "Bluetooth"],
"description": "A powerful home theater system for an immersive audio experience.",
"price": 399.99
},
"CineView 8K TV": {
"name": "CineView 8K TV",
"category": "Televisions and Home Theater Systems",
"brand": "CineView",
"model_number": "CV-8K65",
"warranty": "2 years",
"rating": 4.9,
"features": ["65-inch display", "8K resolution", "HDR", "Smart TV"],
"description": "Experience the future of television with this stunning 8K TV.",
"price": 2999.99
},
"SoundMax Soundbar": {
"name": "SoundMax Soundbar",
"category": "Televisions and Home Theater Systems",
"brand": "SoundMax",
"model_number": "SM-SB50",
"warranty": "1 year",
"rating": 4.3,
"features": ["2.1 channel", "300W output", "Wireless subwoofer", "Bluetooth"],
"description": "Upgrade your TV's audio with this sleek and powerful soundbar.",
"price": 199.99
},
"CineView OLED TV": {
"name": "CineView OLED TV",
"category": "Televisions and Home Theater Systems",
"brand": "CineView",
"model_number": "CV-OLED55",
"warranty": "2 years",
"rating": 4.7,
"features": ["55-inch display", "4K resolution", "HDR", "Smart TV"],
"description": "Experience true blacks and vibrant colors with this OLED TV.",
"price": 1499.99
},
"GameSphere X": {
"name": "GameSphere X",
"category": "Gaming Consoles and Accessories",
"brand": "GameSphere",
"model_number": "GS-X",
"warranty": "1 year",
"rating": 4.9,
"features": ["4K gaming", "1TB storage", "Backward compatibility", "Online multiplayer"],
"description": "A next-generation gaming console for the ultimate gaming experience.",
"price": 499.99
},
"ProGamer Controller": {
"name": "ProGamer Controller",
"category": "Gaming Consoles and Accessories",
"brand": "ProGamer",
"model_number": "PG-C100",
"warranty": "1 year",
"rating": 4.2,
"features": ["Ergonomic design", "Customizable buttons", "Wireless", "Rechargeable battery"],
"description": "A high-quality gaming controller for precision and comfort.",
"price": 59.99
},
"GameSphere Y": {
"name": "GameSphere Y",
"category": "Gaming Consoles and Accessories",
"brand": "GameSphere",
"model_number": "GS-Y",
"warranty": "1 year",
"rating": 4.8,
"features": ["4K gaming", "500GB storage", "Backward compatibility", "Online multiplayer"],
"description": "A compact gaming console with powerful performance.",
"price": 399.99
},
"ProGamer Racing Wheel": {
"name": "ProGamer Racing Wheel",
"category": "Gaming Consoles and Accessories",
"brand": "ProGamer",
"model_number": "PG-RW200",
"warranty": "1 year",
"rating": 4.5,
"features": ["Force feedback", "Adjustable pedals", "Paddle shifters", "Compatible with GameSphere X"],
"description": "Enhance your racing games with this realistic racing wheel.",
"price": 249.99
},
"GameSphere VR Headset": {
"name": "GameSphere VR Headset",
"category": "Gaming Consoles and Accessories",
"brand": "GameSphere",
"model_number": "GS-VR",
"warranty": "1 year",
"rating": 4.6,
"features": ["Immersive VR experience", "Built-in headphones", "Adjustable headband", "Compatible with GameSphere X"],
"description": "Step into the world of virtual reality with this comfortable VR headset.",
"price": 299.99
},
"AudioPhonic Noise-Canceling Headphones": {
"name": "AudioPhonic Noise-Canceling Headphones",
"category": "Audio Equipment",
"brand": "AudioPhonic",
"model_number": "AP-NC100",
"warranty": "1 year",
"rating": 4.6,
"features": ["Active noise-canceling", "Bluetooth", "20-hour battery life", "Comfortable fit"],
"description": "Experience immersive sound with these noise-canceling headphones.",
"price": 199.99
},
"WaveSound Bluetooth Speaker": {
"name": "WaveSound Bluetooth Speaker",
"category": "Audio Equipment",
"brand": "WaveSound",
"model_number": "WS-BS50",
"warranty": "1 year",
"rating": 4.5,
"features": ["Portable", "10-hour battery life", "Water-resistant", "Built-in microphone"],
"description": "A compact and versatile Bluetooth speaker for music on the go.",
"price": 49.99
},
"AudioPhonic True Wireless Earbuds": {
"name": "AudioPhonic True Wireless Earbuds",
"category": "Audio Equipment",
"brand": "AudioPhonic",
"model_number": "AP-TW20",
"warranty": "1 year",
"rating": 4.4,
"features": ["True wireless", "Bluetooth 5.0", "Touch controls", "18-hour battery life"],
"description": "Enjoy music without wires with these comfortable true wireless earbuds.",
"price": 79.99
},
"WaveSound Soundbar": {
"name": "WaveSound Soundbar",
"category": "Audio Equipment",
"brand": "WaveSound",
"model_number": "WS-SB40",
"warranty": "1 year",
"rating": 4.3,
"features": ["2.0 channel", "80W output", "Bluetooth", "Wall-mountable"],
"description": "Upgrade your TV's audio with this slim and powerful soundbar.",
"price": 99.99
},
"AudioPhonic Turntable": {
"name": "AudioPhonic Turntable",
"category": "Audio Equipment",
"brand": "AudioPhonic",
"model_number": "AP-TT10",
"warranty": "1 year",
"rating": 4.2,
"features": ["3-speed", "Built-in speakers", "Bluetooth", "USB recording"],
"description": "Rediscover your vinyl collection with this modern turntable.",
"price": 149.99
},
"FotoSnap DSLR Camera": {
"name": "FotoSnap DSLR Camera",
"category": "Cameras and Camcorders",
"brand": "FotoSnap",
"model_number": "FS-DSLR200",
"warranty": "1 year",
"rating": 4.7,
"features": ["24.2MP sensor", "1080p video", "3-inch LCD", "Interchangeable lenses"],
"description": "Capture stunning photos and videos with this versatile DSLR camera.",
"price": 599.99
},
"ActionCam 4K": {
"name": "ActionCam 4K",
"category": "Cameras and Camcorders",
"brand": "ActionCam",
"model_number": "AC-4K",
"warranty": "1 year",
"rating": 4.4,
"features": ["4K video", "Waterproof", "Image stabilization", "Wi-Fi"],
"description": "Record your adventures with this rugged and compact 4K action camera.",
"price": 299.99
},
"FotoSnap Mirrorless Camera": {
"name": "FotoSnap Mirrorless Camera",
"category": "Cameras and Camcorders",
"brand": "FotoSnap",
"model_number": "FS-ML100",
"warranty": "1 year",
"rating": 4.6,
"features": ["20.1MP sensor", "4K video", "3-inch touchscreen", "Interchangeable lenses"],
"description": "A compact and lightweight mirrorless camera with advanced features.",
"price": 799.99
},
"ZoomMaster Camcorder": {
"name": "ZoomMaster Camcorder",
"category": "Cameras and Camcorders",
"brand": "ZoomMaster",
"model_number": "ZM-CM50",
"warranty": "1 year",
"rating": 4.3,
"features": ["1080p video", "30x optical zoom", "3-inch LCD", "Image stabilization"],
"description": "Capture life's moments with this easy-to-use camcorder.",
"price": 249.99
},
"FotoSnap Instant Camera": {
"name": "FotoSnap Instant Camera",
"category": "Cameras and Camcorders",
"brand": "FotoSnap",
"model_number": "FS-IC10",
"warranty": "1 year",
"rating": 4.1,
"features": ["Instant prints", "Built-in flash", "Selfie mirror", "Battery-powered"],
"description": "Create instant memories with this fun and portable instant camera.",
"price": 69.99
}
}
products_file = 'products.json'
with open(products_file, 'w') as file:
json.dump(products, file)
return products

View File

@ -0,0 +1,760 @@
import json
import openai
from collections import defaultdict
# 商品和目录的数据文件
products_file = 'products_zh.json'
categories_file = 'categories_zh.json'
# 分隔符
delimiter = "####"
# 第二步(抽取商品)系统信息文本
step_2_system_message_content = f"""
您将获得一次客户服务对话。最近的用户查询将使用{delimiter}字符进行分隔。
输出一个Python对象列表其中每个对象具有以下格式
'category': <包括以下几个类别Computers and Laptops、martphones and Accessories、elevisions and Home Theater Systems、elevisions and Home Theater Systems、elevisions and Home Theater Systems、'category': <包括以下几个类别Computers and Laptops、martphones and Accessories、elevisions and Home Theater Systems、elevisions and Home Theater Systems、elevisions and Home Theater Systems、相机和摄像机>,
或者
'products': <必须是下面的允许产品列表中找到的产品>
类别和产品必须在客户服务查询中找到。
如果提到了产品,它必须与下面的允许产品列表中的正确类别相关联。
如果未找到任何产品或类别,请输出一个空列表。
只列出之前对话的早期部分未提及和讨论的产品和类别。
允许的产品:
Computers and Laptops类别
TechPro Ultrabook
BlueWave Gaming Laptop
PowerLite Convertible
TechPro Desktop
BlueWave Chromebook
Smartphones and Accessories类别
SmartX ProPhone
MobiTech PowerCase
SmartX MiniPhone
MobiTech Wireless Charger
SmartX EarBuds
Televisions and Home Theater Systems类别
CineView 4K TV
SoundMax Home Theater
CineView 8K TV
SoundMax Soundbar
CineView OLED TV
Gaming Consoles and Accessories类别
GameSphere X
ProGamer Controller
GameSphere Y
ProGamer Racing Wheel
GameSphere VR Headset
Audio Equipment类别
AudioPhonic Noise-Canceling Headphones
WaveSound Bluetooth Speaker
AudioPhonic True Wireless Earbuds
WaveSound Soundbar
AudioPhonic Turntable
Cameras and Camcorders类别
FotoSnap DSLR Camera
ActionCam 4K
FotoSnap Mirrorless Camera
ZoomMaster Camcorder
FotoSnap Instant Camera
只输出对象列表,不包含其他内容。
"""
step_2_system_message = {'role':'system', 'content': step_2_system_message_content}
# 第四步(生成用户回答)的系统信息
step_4_system_message_content = f"""
你是一家大型电子商店的客户服务助理。
以友好和乐于助人的语气回答,回答保持简洁明了。
确保让用户提出相关的后续问题。
"""
step_4_system_message = {'role':'system', 'content': step_4_system_message_content}
# 第六步(验证模型回答)的系统信息
step_6_system_message_content = f"""
你是一个助手,评估客户服务代理的回答是否足够回答客户的问题,并验证助手从产品信息中引用的所有事实是否正确。
对话历史、产品信息、用户和客户服务代理的消息将用```进行分隔。
请用一个字母回答,不带标点符号:
Y - 如果输出足够回答问题,并且回答正确使用了产品信息
N - 输出不足够回答问题,或者没有正确使用产品信息
只输出一个字母。
"""
step_6_system_message = {'role':'system', 'content': step_6_system_message_content}
# 使用 ChatCompletion 接口
def get_completion_from_messages(messages, model="gpt-3.5-turbo", temperature=0, max_tokens=500):
response = openai.ChatCompletion.create(
model=model,
messages=messages,
temperature=temperature,
max_tokens=max_tokens,
)
return response.choices[0].message["content"]
# 创建目录(如果没有本地目录文件,需要创建一份)
def create_categories():
categories_dict = {
'Billing': [
'Unsubscribe or upgrade',
'Add a payment method',
'Explanation for charge',
'Dispute a charge'],
'Technical Support':[
'General troubleshooting',
'Device compatibility',
'Software updates'],
'Account Management':[
'Password reset',
'Update personal information',
'Close account',
'Account security'],
'General Inquiry':[
'Product information',
'Pricing',
'Feedback',
'Speak to a human']
}
with open(categories_file, 'w') as file:
json.dump(categories_dict, file)
return categories_dict
# 获取目录数据
def get_categories():
with open(categories_file, 'r') as file:
categories = json.load(file)
return categories
# 获取商品列表
def get_product_list():
"""
具体原理参见第四节课
"""
products = get_products()
product_list = []
for product in products.keys():
product_list.append(product)
return product_list
# 获取商品和目录
def get_products_and_category():
"""
具体原理参见第五节课
"""
products = get_products()
products_by_category = defaultdict(list)
for product_name, product_info in products.items():
category = product_info.get('类别')
if category:
products_by_category[category].append(product_info.get('名称'))
return dict(products_by_category)
# 从商品数据中获取
def get_products():
with open(products_file, 'r') as file:
products = json.load(file)
return products
# 从用户问题中抽取商品和类别
def find_category_and_product(user_input,products_and_category):
delimiter = "####"
system_message = f"""
您将获得客户服务查询。
客户服务查询将使用{delimiter}字符分隔。
输出一个可解析的Python列表列表每一个元素是一个JSON对象每个对象具有以下格式
'category': <包括以下几个类别Computers and LaptopsSmartphones and AccessoriesTelevisions and Home Theater SystemsGaming Consoles and AccessoriesAudio EquipmentCameras and Camcorders>
以及
'products': <必须是下面的允许产品列表中找到的产品列表>
其中类别和产品必须在客户服务查询中找到。
如果提到了产品,则必须将其与允许产品列表中的正确类别关联。
如果未找到任何产品或类别,则输出一个空列表。
除了列表外,不要输出其他任何信息!
允许的产品以JSON格式提供。
每个项的键表示类别。
每个项的值是该类别中的产品列表。
允许的产品:{products_and_category}
"""
messages = [
{'role':'system', 'content': system_message},
{'role':'user', 'content': f"{delimiter}{user_input}{delimiter}"},
]
return get_completion_from_messages(messages)
# 相比上一个函数,可获取的商品直接在 template 中限定
def find_category_and_product_only(user_input,products_and_category):
delimiter = "####"
system_message = f"""
您将获得客户服务查询。
客户服务查询将使用{delimiter}字符作为分隔符。
请仅输出一个可解析的Python列表列表每一个元素是一个JSON对象每个对象具有以下格式
'category': <包括以下几个类别Computers and Laptops、Smartphones and Accessories、Televisions and Home Theater Systems、Gaming Consoles and Accessories、Audio Equipment、Cameras and Camcorders>,
以及
'products': <必须是下面的允许产品列表中找到的产品列表>
类别和产品必须在客户服务查询中找到。
如果提到了某个产品,它必须与允许产品列表中的正确类别关联。
如果未找到任何产品或类别,则输出一个空列表。
除了列表外,不要输出其他任何信息!
允许的产品:
Computers and Laptops category:
TechPro Ultrabook
BlueWave Gaming Laptop
PowerLite Convertible
TechPro Desktop
BlueWave Chromebook
Smartphones and Accessories category:
SmartX ProPhone
MobiTech PowerCase
SmartX MiniPhone
MobiTech Wireless Charger
SmartX EarBuds
Televisions and Home Theater Systems category:
CineView 4K TV
SoundMax Home Theater
CineView 8K TV
SoundMax Soundbar
CineView OLED TV
Gaming Consoles and Accessories category:
GameSphere X
ProGamer Controller
GameSphere Y
ProGamer Racing Wheel
GameSphere VR Headset
Audio Equipment category:
AudioPhonic Noise-Canceling Headphones
WaveSound Bluetooth Speaker
AudioPhonic True Wireless Earbuds
WaveSound Soundbar
AudioPhonic Turntable
Cameras and Camcorders category:
FotoSnap DSLR Camera
ActionCam 4K
FotoSnap Mirrorless Camera
ZoomMaster Camcorder
FotoSnap Instant Camera
只输出对象列表,不包含其他内容。
"""
messages = [
{'role':'system', 'content': system_message},
{'role':'user', 'content': f"{delimiter}{user_input}{delimiter}"},
]
return get_completion_from_messages(messages)
# 从问题中抽取商品
def get_products_from_query(user_msg):
"""
代码来自于第五节课
"""
products_and_category = get_products_and_category()
delimiter = "####"
system_message = f"""
您将获得客户服务查询。
客户服务查询将使用{delimiter}字符作为分隔符。
请仅输出一个可解析的Python列表列表每一个元素是一个JSON对象每个对象具有以下格式
'category': <包括以下几个类别Computers and Laptops、Smartphones and Accessories、Televisions and Home Theater Systems、Gaming Consoles and Accessories、Audio Equipment、Cameras and Camcorders>,
以及
'products': <必须是下面的允许产品列表中找到的产品列表>
类别和产品必须在客户服务查询中找到。
如果提到了某个产品,它必须与允许产品列表中的正确类别关联。
如果未找到任何产品或类别,则输出一个空列表。
除了列表外,不要输出其他任何信息!
允许的产品以JSON格式提供。
每个项目的键表示类别。
每个项目的值是该类别中的产品列表。
以下是允许的产品:{products_and_category}
"""
messages = [
{'role':'system', 'content': system_message},
{'role':'user', 'content': f"{delimiter}{user_msg}{delimiter}"},
]
category_and_product_response = get_completion_from_messages(messages)
return category_and_product_response
# 商品信息的搜索
def get_product_by_name(name):
products = get_products()
return products.get(name, None)
def get_products_by_category(category):
products = get_products()
return [product for product in products.values() if product["category"] == category]
def get_mentioned_product_info(data_list):
"""
具体原理参见第五、六节课
"""
product_info_l = []
if data_list is None:
return product_info_l
for data in data_list:
try:
if "products" in data:
products_list = data["products"]
for product_name in products_list:
product = get_product_by_name(product_name)
if product:
product_info_l.append(product)
else:
print(f"错误: 商品 '{product_name}' 未找到")
elif "category" in data:
category_name = data["category"]
category_products = get_products_by_category(category_name)
for product in category_products:
product_info_l.append(product)
else:
print("错误:非法的商品格式")
except Exception as e:
print(f"Error: {e}")
return product_info_l
# 以下函数原理参见第五节课
def read_string_to_list(input_string):
if input_string is None:
return None
try:
input_string = input_string.replace("'", "\"") # Replace single quotes with double quotes for valid JSON
data = json.loads(input_string)
return data
except json.JSONDecodeError:
print(input_string)
print("错误:非法的 Json 格式")
return None
def generate_output_string(data_list):
output_string = ""
if data_list is None:
return output_string
# print(data_list)
for data in data_list:
try:
if "products" in data:
# print(data)
products_list = data["products"]
for product_name in products_list:
product = get_product_by_name(product_name)
if product:
output_string += json.dumps(product, indent=4) + "\n"
else:
print(f"错误: 商品 '{product_name}' 没有找到")
elif "category" in data:
category_name = data["category"]
category_products = get_products_by_category(category_name)
for product in category_products:
output_string += json.dumps(product, indent=4) + "\n"
else:
print("错误:非法的商品格式")
except Exception as e:
print(f"Error: {e}")
return output_string
# Example usage:
#product_information_for_user_message_1 = generate_output_string(category_and_product_list)
#print(product_information_for_user_message_1)
# 回答用户问题
def answer_user_msg(user_msg,product_info):
"""
代码参见第五节课
"""
delimiter = "####"
system_message = f"""
您是一家大型电子商店的客户服务助理。\
请用友好和乐于助人的口吻回答问题,提供简洁明了的答案。\
确保向用户提出相关的后续问题。
"""
# user_msg = f"""
# tell me about the smartx pro phone and the fotosnap camera, the dslr one. Also what tell me about your tvs"""
messages = [
{'role':'system', 'content': system_message},
{'role':'user', 'content': f"{delimiter}{user_msg}{delimiter}"},
{'role':'assistant', 'content': f"相关产品信息:\n{product_info}"},
]
response = get_completion_from_messages(messages)
return response
# 创建并存入商品数据
def create_products():
# product information
# fun fact: all these products are fake and were generated by a language model
products = {
"TechPro Ultrabook": {
"name": "TechPro Ultrabook",
"category": "Computers and Laptops",
"brand": "TechPro",
"model_number": "TP-UB100",
"warranty": "1 year",
"rating": 4.5,
"features": ["13.3-inch display", "8GB RAM", "256GB SSD", "Intel Core i5 processor"],
"description": "A sleek and lightweight ultrabook for everyday use.",
"price": 799.99
},
"BlueWave Gaming Laptop": {
"name": "BlueWave Gaming Laptop",
"category": "Computers and Laptops",
"brand": "BlueWave",
"model_number": "BW-GL200",
"warranty": "2 years",
"rating": 4.7,
"features": ["15.6-inch display", "16GB RAM", "512GB SSD", "NVIDIA GeForce RTX 3060"],
"description": "A high-performance gaming laptop for an immersive experience.",
"price": 1199.99
},
"PowerLite Convertible": {
"name": "PowerLite Convertible",
"category": "Computers and Laptops",
"brand": "PowerLite",
"model_number": "PL-CV300",
"warranty": "1 year",
"rating": 4.3,
"features": ["14-inch touchscreen", "8GB RAM", "256GB SSD", "360-degree hinge"],
"description": "A versatile convertible laptop with a responsive touchscreen.",
"price": 699.99
},
"TechPro Desktop": {
"name": "TechPro Desktop",
"category": "Computers and Laptops",
"brand": "TechPro",
"model_number": "TP-DT500",
"warranty": "1 year",
"rating": 4.4,
"features": ["Intel Core i7 processor", "16GB RAM", "1TB HDD", "NVIDIA GeForce GTX 1660"],
"description": "A powerful desktop computer for work and play.",
"price": 999.99
},
"BlueWave Chromebook": {
"name": "BlueWave Chromebook",
"category": "Computers and Laptops",
"brand": "BlueWave",
"model_number": "BW-CB100",
"warranty": "1 year",
"rating": 4.1,
"features": ["11.6-inch display", "4GB RAM", "32GB eMMC", "Chrome OS"],
"description": "A compact and affordable Chromebook for everyday tasks.",
"price": 249.99
},
"SmartX ProPhone": {
"name": "SmartX ProPhone",
"category": "Smartphones and Accessories",
"brand": "SmartX",
"model_number": "SX-PP10",
"warranty": "1 year",
"rating": 4.6,
"features": ["6.1-inch display", "128GB storage", "12MP dual camera", "5G"],
"description": "A powerful smartphone with advanced camera features.",
"price": 899.99
},
"MobiTech PowerCase": {
"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
},
"SmartX MiniPhone": {
"name": "SmartX MiniPhone",
"category": "Smartphones and Accessories",
"brand": "SmartX",
"model_number": "SX-MP5",
"warranty": "1 year",
"rating": 4.2,
"features": ["4.7-inch display", "64GB storage", "8MP camera", "4G"],
"description": "A compact and affordable smartphone for basic tasks.",
"price": 399.99
},
"MobiTech Wireless Charger": {
"name": "MobiTech Wireless Charger",
"category": "Smartphones and Accessories",
"brand": "MobiTech",
"model_number": "MT-WC10",
"warranty": "1 year",
"rating": 4.5,
"features": ["10W fast charging", "Qi-compatible", "LED indicator", "Compact design"],
"description": "A convenient wireless charger for a clutter-free workspace.",
"price": 29.99
},
"SmartX EarBuds": {
"name": "SmartX EarBuds",
"category": "Smartphones and Accessories",
"brand": "SmartX",
"model_number": "SX-EB20",
"warranty": "1 year",
"rating": 4.4,
"features": ["True wireless", "Bluetooth 5.0", "Touch controls", "24-hour battery life"],
"description": "Experience true wireless freedom with these comfortable earbuds.",
"price": 99.99
},
"CineView 4K TV": {
"name": "CineView 4K TV",
"category": "Televisions and Home Theater Systems",
"brand": "CineView",
"model_number": "CV-4K55",
"warranty": "2 years",
"rating": 4.8,
"features": ["55-inch display", "4K resolution", "HDR", "Smart TV"],
"description": "A stunning 4K TV with vibrant colors and smart features.",
"price": 599.99
},
"SoundMax Home Theater": {
"name": "SoundMax Home Theater",
"category": "Televisions and Home Theater Systems",
"brand": "SoundMax",
"model_number": "SM-HT100",
"warranty": "1 year",
"rating": 4.4,
"features": ["5.1 channel", "1000W output", "Wireless subwoofer", "Bluetooth"],
"description": "A powerful home theater system for an immersive audio experience.",
"price": 399.99
},
"CineView 8K TV": {
"name": "CineView 8K TV",
"category": "Televisions and Home Theater Systems",
"brand": "CineView",
"model_number": "CV-8K65",
"warranty": "2 years",
"rating": 4.9,
"features": ["65-inch display", "8K resolution", "HDR", "Smart TV"],
"description": "Experience the future of television with this stunning 8K TV.",
"price": 2999.99
},
"SoundMax Soundbar": {
"name": "SoundMax Soundbar",
"category": "Televisions and Home Theater Systems",
"brand": "SoundMax",
"model_number": "SM-SB50",
"warranty": "1 year",
"rating": 4.3,
"features": ["2.1 channel", "300W output", "Wireless subwoofer", "Bluetooth"],
"description": "Upgrade your TV's audio with this sleek and powerful soundbar.",
"price": 199.99
},
"CineView OLED TV": {
"name": "CineView OLED TV",
"category": "Televisions and Home Theater Systems",
"brand": "CineView",
"model_number": "CV-OLED55",
"warranty": "2 years",
"rating": 4.7,
"features": ["55-inch display", "4K resolution", "HDR", "Smart TV"],
"description": "Experience true blacks and vibrant colors with this OLED TV.",
"price": 1499.99
},
"GameSphere X": {
"name": "GameSphere X",
"category": "Gaming Consoles and Accessories",
"brand": "GameSphere",
"model_number": "GS-X",
"warranty": "1 year",
"rating": 4.9,
"features": ["4K gaming", "1TB storage", "Backward compatibility", "Online multiplayer"],
"description": "A next-generation gaming console for the ultimate gaming experience.",
"price": 499.99
},
"ProGamer Controller": {
"name": "ProGamer Controller",
"category": "Gaming Consoles and Accessories",
"brand": "ProGamer",
"model_number": "PG-C100",
"warranty": "1 year",
"rating": 4.2,
"features": ["Ergonomic design", "Customizable buttons", "Wireless", "Rechargeable battery"],
"description": "A high-quality gaming controller for precision and comfort.",
"price": 59.99
},
"GameSphere Y": {
"name": "GameSphere Y",
"category": "Gaming Consoles and Accessories",
"brand": "GameSphere",
"model_number": "GS-Y",
"warranty": "1 year",
"rating": 4.8,
"features": ["4K gaming", "500GB storage", "Backward compatibility", "Online multiplayer"],
"description": "A compact gaming console with powerful performance.",
"price": 399.99
},
"ProGamer Racing Wheel": {
"name": "ProGamer Racing Wheel",
"category": "Gaming Consoles and Accessories",
"brand": "ProGamer",
"model_number": "PG-RW200",
"warranty": "1 year",
"rating": 4.5,
"features": ["Force feedback", "Adjustable pedals", "Paddle shifters", "Compatible with GameSphere X"],
"description": "Enhance your racing games with this realistic racing wheel.",
"price": 249.99
},
"GameSphere VR Headset": {
"name": "GameSphere VR Headset",
"category": "Gaming Consoles and Accessories",
"brand": "GameSphere",
"model_number": "GS-VR",
"warranty": "1 year",
"rating": 4.6,
"features": ["Immersive VR experience", "Built-in headphones", "Adjustable headband", "Compatible with GameSphere X"],
"description": "Step into the world of virtual reality with this comfortable VR headset.",
"price": 299.99
},
"AudioPhonic Noise-Canceling Headphones": {
"name": "AudioPhonic Noise-Canceling Headphones",
"category": "Audio Equipment",
"brand": "AudioPhonic",
"model_number": "AP-NC100",
"warranty": "1 year",
"rating": 4.6,
"features": ["Active noise-canceling", "Bluetooth", "20-hour battery life", "Comfortable fit"],
"description": "Experience immersive sound with these noise-canceling headphones.",
"price": 199.99
},
"WaveSound Bluetooth Speaker": {
"name": "WaveSound Bluetooth Speaker",
"category": "Audio Equipment",
"brand": "WaveSound",
"model_number": "WS-BS50",
"warranty": "1 year",
"rating": 4.5,
"features": ["Portable", "10-hour battery life", "Water-resistant", "Built-in microphone"],
"description": "A compact and versatile Bluetooth speaker for music on the go.",
"price": 49.99
},
"AudioPhonic True Wireless Earbuds": {
"name": "AudioPhonic True Wireless Earbuds",
"category": "Audio Equipment",
"brand": "AudioPhonic",
"model_number": "AP-TW20",
"warranty": "1 year",
"rating": 4.4,
"features": ["True wireless", "Bluetooth 5.0", "Touch controls", "18-hour battery life"],
"description": "Enjoy music without wires with these comfortable true wireless earbuds.",
"price": 79.99
},
"WaveSound Soundbar": {
"name": "WaveSound Soundbar",
"category": "Audio Equipment",
"brand": "WaveSound",
"model_number": "WS-SB40",
"warranty": "1 year",
"rating": 4.3,
"features": ["2.0 channel", "80W output", "Bluetooth", "Wall-mountable"],
"description": "Upgrade your TV's audio with this slim and powerful soundbar.",
"price": 99.99
},
"AudioPhonic Turntable": {
"name": "AudioPhonic Turntable",
"category": "Audio Equipment",
"brand": "AudioPhonic",
"model_number": "AP-TT10",
"warranty": "1 year",
"rating": 4.2,
"features": ["3-speed", "Built-in speakers", "Bluetooth", "USB recording"],
"description": "Rediscover your vinyl collection with this modern turntable.",
"price": 149.99
},
"FotoSnap DSLR Camera": {
"name": "FotoSnap DSLR Camera",
"category": "Cameras and Camcorders",
"brand": "FotoSnap",
"model_number": "FS-DSLR200",
"warranty": "1 year",
"rating": 4.7,
"features": ["24.2MP sensor", "1080p video", "3-inch LCD", "Interchangeable lenses"],
"description": "Capture stunning photos and videos with this versatile DSLR camera.",
"price": 599.99
},
"ActionCam 4K": {
"name": "ActionCam 4K",
"category": "Cameras and Camcorders",
"brand": "ActionCam",
"model_number": "AC-4K",
"warranty": "1 year",
"rating": 4.4,
"features": ["4K video", "Waterproof", "Image stabilization", "Wi-Fi"],
"description": "Record your adventures with this rugged and compact 4K action camera.",
"price": 299.99
},
"FotoSnap Mirrorless Camera": {
"name": "FotoSnap Mirrorless Camera",
"category": "Cameras and Camcorders",
"brand": "FotoSnap",
"model_number": "FS-ML100",
"warranty": "1 year",
"rating": 4.6,
"features": ["20.1MP sensor", "4K video", "3-inch touchscreen", "Interchangeable lenses"],
"description": "A compact and lightweight mirrorless camera with advanced features.",
"price": 799.99
},
"ZoomMaster Camcorder": {
"name": "ZoomMaster Camcorder",
"category": "Cameras and Camcorders",
"brand": "ZoomMaster",
"model_number": "ZM-CM50",
"warranty": "1 year",
"rating": 4.3,
"features": ["1080p video", "30x optical zoom", "3-inch LCD", "Image stabilization"],
"description": "Capture life's moments with this easy-to-use camcorder.",
"price": 249.99
},
"FotoSnap Instant Camera": {
"name": "FotoSnap Instant Camera",
"category": "Cameras and Camcorders",
"brand": "FotoSnap",
"model_number": "FS-IC10",
"warranty": "1 year",
"rating": 4.1,
"features": ["Instant prints", "Built-in flash", "Selfie mirror", "Battery-powered"],
"description": "Create instant memories with this fun and portable instant camera.",
"price": 69.99
}
}
products_file = 'products.json'
with open(products_file, 'w') as file:
json.dump(products, file)
return products