小智头像图片
AI教程 2025年01月15日
0 收藏 0 点赞 420 浏览 9291 个字
摘要 :

面向开发者的LLM入门课程-处理输入链式英文版: 英文版 1.提取产品和类别 delimiter = “####” system_message = f””” You will be provi……

哈喽!伙伴们,我是小智,你们的AI向导。欢迎来到每日的AI学习时间。今天,我们将一起深入AI的奇妙世界,探索“面向开发者的LLM入门课程-处理输入链式英文版”,并学会本篇文章中所讲的全部知识点。还是那句话“不必远征未知,只需唤醒你的潜能!”跟着小智的步伐,我们终将学有所成,学以致用,并发现自身的更多可能性。话不多说,现在就让我们开始这场激发潜能的AI学习之旅吧。

面向开发者的LLM入门课程-处理输入链式英文版

面向开发者的LLM入门课程-处理输入链式英文版:

英文版

1.提取产品和类别

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’: ,
and
‘products’:
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:
Products under Computers and Laptops category:
TechPro Ultrabook
BlueWave Gaming Laptop
PowerLite Convertible
TechPro Desktop
BlueWave Chromebook
Products under Smartphones and Accessories category:
SmartX ProPhone
MobiTech PowerCase
SmartX MiniPhone
MobiTech Wireless Charger
SmartX EarBuds
Products under Televisions and Home Theater Systems category:
CineView 4K TV
SoundMax Home Theater
CineView 8K TV
SoundMax Soundbar
CineView OLED TV
Products under Gaming Consoles and Accessories category:
GameSphere X
ProGamer Controller
GameSphere Y
ProGamer Racing Wheel
GameSphere VR Headset
Products under Audio Equipment category:
AudioPhonic Noise-Canceling Headphones
WaveSound Bluetooth Speaker
AudioPhonic True Wireless Earbuds
WaveSound Soundbar
AudioPhonic Turntable
Products under 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.
“””
user_message_1 = f”””
tell me about the smartx pro phone and
the fotosnap camera, the dslr one.
Also tell me about your tvs “””
messages = [
{‘role’:’system’,
‘content’: system_message},
{‘role’:’user’,
‘content’: f”{delimiter}{user_message_1}{delimiter}”},
]
category_and_product_response_1 = get_completion_from_messages(messages)
category_and_product_response_1

“[{‘category’: ‘Smartphones and Accessories’, ‘products’: [‘SmartX ProPhone’]},
{‘category’: ‘Cameras and Camcorders’, ‘products’: [‘FotoSnap DSLR Camera’]},
{‘category’: ‘Televisions and Home Theater Systems’, ‘products’: []}]”

user_message_2 = f”””
my router isn’t working”””
messages = [
{‘role’:’system’,
‘content’: system_message},
{‘role’:’user’,
‘content’: f”{delimiter}{user_message_2}{delimiter}”},
]
response = get_completion_from_messages(messages)
print(response)

[]

2.检索详细信息

with open(“products.json”, “r”) as file:
products = josn.load(file)

def get_product_by_name(name):
return products.get(name, None)
def get_products_by_category(category):
return [product for product in products.values() if product[“category”] ==
category]

get_product_by_name(“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}

get_products_by_category(“Computers and Laptops”)

[{‘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},
{‘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},
{‘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},
{‘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},
{‘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}]

3.解析输入字符串

def read_string_to_list(input_string):
“””
将输入的字符串转换为 Python 列表。
参数:
input_string: 输入的字符串,应为有效的 JSON 格式。
返回:
list 或 None: 如果输入字符串有效,则返回对应的 Python 列表,否则返回 None。
“””
if input_string is None:
return None
try:
# 将输入字符串中的单引号替换为双引号,以满足 JSON 格式的要求
input_string = input_string.replace(“‘”, “””)
data = json.loads(input_string)
return data
except json.JSONDecodeError:
print(“Error: Invalid JSON string”)
return None

category_and_product_list = read_string_to_list(category_and_product_response_1)
category_and_product_list

[{‘category’: ‘Smartphones and Accessories’, ‘products’: [‘SmartX ProPhone’]},
{‘category’: ‘Cameras and Camcorders’, ‘products’: [‘FotoSnap DSLR Camera’]},
{‘category’: ‘Televisions and Home Theater Systems’, ‘products’: []}]

4.进行检索

def generate_output_string(data_list):
“””
根据输入的数据列表生成包含产品或类别信息的字符串。
参数:
data_list: 包含字典的列表,每个字典都应包含 “products” 或 “category” 的键。
返回:
output_string: 包含产品或类别信息的字符串。
“””
output_string = “”
if data_list is None:
return output_string
for data in data_list:
try:
if “products” in data and data[“products”]:
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,
ensure_ascii=False) + “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,
ensure_ascii=False) + “n”
else:
print(“Error: Invalid object format”)
except Exception as e:
print(f”Error: {e}”)
return output_string

product_information_for_user_message_1 =
generate_output_string(category_and_product_list)
print(product_information_for_user_message_1)

{
“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
}
{
“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
}
{
“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
}
{
“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
}
{
“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
}
{
“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
}
{
“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
}

5.生成用户查询的答案

system_message = 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.
“””
user_message_1 = f”””
tell me about the smartx pro phone and
the fotosnap camera, the dslr one.
Also tell me about your tvs”””
messages = [{‘role’:’system’,’content’: system_message},
{‘role’:’user’,’content’: user_message_1},
{‘role’:’assistant’,
‘content’: f”””Relevant product information:n
{product_information_for_user_message_1}”””}]
final_response = get_completion_from_messages(messages)
print(final_response)

The SmartX ProPhone is a powerful smartphone with a 6.1-inch display, 128GB
storage, a 12MP dual camera, and 5G capability. It is priced at $899.99 and comes
with a 1-year warranty.
The FotoSnap DSLR Camera is a versatile camera with a 24.2MP sensor, 1080p video
recording, a 3-inch LCD screen, and interchangeable lenses. It is priced at
$599.99 and also comes with a 1-year warranty.
As for our TVs, we have a range of options. The CineView 4K TV is a 55-inch TV
with 4K resolution, HDR, and smart TV features. It is priced at $599.99 and comes
with a 2-year warranty.
We also have the CineView 8K TV, which is a 65-inch TV with 8K resolution, HDR,
and smart TV features. It is priced at $2999.99 and also comes with a 2-year
warranty.
Lastly, we have the CineView OLED TV, which is a 55-inch TV with 4K resolution,
HDR, and smart TV features. It is priced at $1499.99 and comes with a 2-year
warranty.
Is there anything specific you would like to know about these products?

面向开发者的LLM入门课程-检查有害内容
面向开发者的LLM入门课程-检查有害内容:检查结果 随着我们深入的学习,本教程将引领你了解如何评估系统生成的输出。在任何场景中,...

嘿,伙伴们,今天我们的AI探索之旅已经圆满结束。关于“面向开发者的LLM入门课程-处理输入链式英文版”的内容已经分享给大家了。感谢你们的陪伴,希望这次旅程让你对AI能够更了解、更喜欢。谨记,精准提问是解锁AI潜能的钥匙哦!如果有小伙伴想要了解学习更多的AI知识,请关注我们的官网“AI智研社”,保证让你收获满满呦!

微信打赏二维码 微信扫一扫

支付宝打赏二维码 支付宝扫一扫

版权: 转载请注明出处:https://www.ai-blog.cn/2578.html

相关推荐
03-23

如何在 Java 中基于 LangChain 编写大语言模型应用: 在本教程中,我们将会研究 LangChain 的细节…

小智头像图片
153
03-12

DeepSeek企业级部署实战指南: 对于个人开发者或尝鲜者而言,本地想要部署 DeepSeek 有很多种方案…

小智头像图片
97
03-12

如何使用DeepSeek助你增强求职竞争力: 职场篇 常见的简历问题 1. 格式混乱或排版不专业 • 问题:…

小智头像图片
206
03-12

DeepSeek官方提示词:让你的API应用和官方一样强: 本文讨论了DeepSeek官方关于让API应用和官方一…

小智头像图片
101
03-12

关于 DeepSeek 的研究和思考 (Archerman Capital): 关于这几天很火的 DeepSeek, 我们 (Archerman …

小智头像图片
116

AI教程DeepSeek提示词之代码解释: 代码解释​ ​ 对代码进行解释,来帮助理解代码内容。​ ​ ​ 请解…

小智头像图片
123

AI教程DeepSeek提示词之代码改写: 代码改写​ ​ 对代码进行修改,来实现纠错、注释、调优等。​ ​ …

小智头像图片
420

AI教程DeepSeek提示词之代码生成: 代码生成​ ​ 让模型生成一段完成特定功能的代码。​ ​ 用户提示…

小智头像图片
420
发表评论
暂无评论

还没有评论呢,快来抢沙发~

助力原创内容

快速提升站内名气成为大牛

扫描二维码

手机访问本站

二维码
vip弹窗图片