ChatGPT Prompting开发实战(三)

一、关于chaining prompts与CoT的比较

前面谈到的CoT的推理过程,可以比作是一次性就烹调好一顿大餐,那么接下来要说的“chaining prompts”,其背后的理念是分多次来完成这样一项复杂任务,每次只完成其中一步或者一个子任务。核心之处在于,你需要在自己的代码中来维护状态(而不是LLM)。另外可能需要使用到外部的第三方工具,譬如网页搜索或者数据库等等,LLM起到的是驱动引擎的作用。

二、基于chaining prompts案例剖析prompt的分步应用

首先来看这样一个system message样例,在这个prompt中,给出了category和product的设定,提示如果用户问题提到的category或者product在设定列表中不存在,那么返回为空,另外一个product必须关联到一个正确的category:

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, with nothing else.

"""

给出设定的user message如下,调用方法给出查询结果:

打印结果信息如下,格式匹配上面系统的设定:

再给出一个user message:

my router isn't working

这次问题提到的router在系统产品设定中不存在,所以返回一个空的列表:

接下来根据从用户问题中提取的category和product信息来进一步获取products的细节,以下是系统设定的具体内容,为了演示方便,这些产品信息直接以文本的形式呈现:

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

    }

}

然后调用方法根据名称或者产品类别获取具体产品的细节:

输出结果示例如下:

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/118108.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

探索图像数据中的隐藏信息:语义实体识别和关系抽取的奇妙之旅

探索图像数据中的隐藏信息&#xff1a;语义实体识别和关系抽取的奇妙之旅 1. 简介 1.1 背景 关键信息抽取 (Key Information Extraction, KIE)指的是是从文本或者图像中&#xff0c;抽取出关键的信息。针对文档图像的关键信息抽取任务作为OCR的下游任务&#xff0c;存在非常…

2023年的深度学习入门指南(26) - 在自己电脑上运行通义千问7b模型

2023年的深度学习入门指南(26) - 在自己电脑上运行通义千问7b模型 通过量化&#xff0c;通义千问4位量化的模型大小为5.86G&#xff0c;可以在3060等小于16G的家用GPU上也可以运行起来。 通义千问7b的量化运行 通义千问7b提供了4位量化好的Qwen/Qwen-7B-Chat-Int4模型&#…

无涯教程-Android - RadioGroup函数

RadioGroup类用于单选按钮集。 如果我们选中属于某个单选按钮组的一个单选按钮,它将自动取消选中同一组中以前选中的任何单选按钮。 RadioGroup属性 以下是与RadioGroup控制相关的重要属性。您可以查看Android官方文档以获取属性的完整列表以及可以在运行时更改这些属性的相关…

day-07 I/O复用(select)

一.I/O复用 &#xff08;一&#xff09;基于I/O复用的服务器端 1.多进程服务器 每次服务都需要创建一个进程&#xff0c;需要大量的运算和内存空间 2.复用 只需创建一个进程。 3.复用技术在服务器端的应用 &#xff08;二&#xff09;select函数实现服务器端 &#xff08;…

03-基础例程3

基础例程3 01、外部中断 ESP32的外部中断有上升沿、下降沿、低电平、高电平触发模式。 实验目的 使用外部中断功能实现按键控制LED的亮灭 按键按下为0。【即下降沿】 * 接线说明&#xff1a;按键模块-->ESP32 IO* (K1-K4)-->(14,27,26,25)* * …

软件测试Day6|接口测试

学习流程 接口测试流程 需求分析和评审–接口文档分析–编写测试用例–测试用例设计及评审–测试脚本构建–执行测试用例–缺陷管理和回归–测试报告和总结计网基础&#xff08;URL、请求、响应&#xff09; 接口文档解析 拿到一个项目接口之后&#xff0c;先测试业务接口还是…

抽象轻松的C语言

#include <stdio.h> /* 预处理指令*/ /* 函数 */ int main() {int log 3.14;printf("hello word * %d\n easy", log);getchar();/* 获取键盘输入的字母&#xff0c;在这个程序中的作用是防止程序瞬间关闭 */return 0; } 上一篇说过&#xff0c;C程序是C语言的…

21.4 CSS 盒子模型

1. 边框样式 border-style属性: 指定元素的边框样式.常用属性值: - none: 无边框(默认值). - solid: 实线边框. - dotted: 点状边框. - dashed: 虚线边框. - double: 双线边框. - groove: 凹槽状边框. - ridge: 脊状边框. - inset: 内阴影边框. - outset: 外阴影边框.这些值可…

「MySQL-02」数据库的操纵、备份、还原和编码规则

目录 一、库操作 1. 创建数据库 2. 查看所有数据库 3. 删除数据库 4. 修改数据库 5. 进入一个数据库 二、查看和设置数据库的编码规则 1. MySQL的两个编码规则&#xff1a;字符集和校验规则 2. 查看MySQL当前使用的字符集以及校验规则 3. 查看MySQL支持的所有字符集 4. 查看MyS…

肖sir__linux详解__002(系统命令)

linux系统命令 1、df 查看磁盘使用情况 &#xff08;1&#xff09;df 查看磁盘使用情况&#xff08;按kb单位显示&#xff09; &#xff08;2&#xff09;df -h 按单位显示磁盘使用情况 2、top 实时查看动态进程 &#xff08;1&#xff09;top 详解&#xff1a; 第一行&…

为什么要学习C++

操作系统历史 UINX操作系统诞生之初是用汇编语言编写的。随着UNIX的发展&#xff0c;汇编语言的开发效率成为一个瓶颈。寻找新的高效开发语言成为UNIX开发者需要解决的问题。当时BCPL语言成为了当时的选择之一。Ken Thomposn对BCPL进行简化得到了B语言。但是B语言不是直接生成…

【AWS实验】 配置中转网关及对等连接

文章目录 实验概览目标实验环境任务 1&#xff1a;查看网络拓扑并创建基准任务 2&#xff1a;创建中转网关任务 3&#xff1a;创建中转网关挂载任务 4&#xff1a;创建中转网关路由表任务 4.1&#xff1a;创建路由表关联任务 4.2&#xff1a;创建路由传播 任务 5&#xff1a;更…

Android JNI系列详解之ndk-build工具的使用

一、Android项目中使用ndk-build工具编译库文件 之前介绍过CMake编译工具的使用&#xff0c;今天介绍一种ndk自带的编译工具ndk-build的使用。 ndk-build目前主要有两种配置使用方式&#xff1a; 如上图所示&#xff0c;第一种方式是Android.mkApplication.mkgradle的方式生成…

SpringBoot初级开发--服务请求(GET/POST)所有参数的记录管理(8)

服务端在定位错误的时候&#xff0c;有时候要还原现场&#xff0c;这就要把当时的所有入参参数都能记录下来&#xff0c;GET还好说&#xff0c;基本NGINX都会记录。但是POST的请求参数基本不会被记录&#xff0c;这就需要我们通过一些小技巧来记录这些参数&#xff0c;放入日志…

C++ struct 笔记(超级详细)

今日碎碎念&#xff1a;我在学C语言时经常用到结构体struct&#xff0c;之后在写C程序时遇到在struct中定义构造函数和成员函数的情况&#xff0c;这在c语言中是从未遇到过的&#xff0c;觉得奇怪&#xff0c;想到之前并没有真正系统学习C里的struct&#xff0c;有必要今天详细…

企业架构LNMP学习笔记8

1、 运维人员需要考虑安全性、稳定性。 安装&#xff1a; 解压进入到目录&#xff1a; shell > tar zxf php-7.2.12.tar.gz shell > cd php-7.2.12 安装依赖软件&#xff1a; yum -y install libxml2-devel libjpeg-devel libpng-devel freetype-devel curl-devel op…

uniapp 微信小程序 获取用户头像和昵称

一、背景 自2022年10月25日后&#xff0c;小程序 wx.getUserProfile 接口 被收回&#xff0c;通过 wx.getUserInfo 接口获取用户头像将统一返回默认灰色头像&#xff0c;昵称将统一返回 “微信用户”。如需获取用户头像昵称&#xff0c;可以手动获取&#xff0c;具体步骤&…

Java单元测试及常用语句 | 京东物流技术团队

1 前言 编写Java单元测试用例&#xff0c;即把一段复杂的代码拆解成一系列简单的单元测试用例&#xff0c;并且无需启动服务&#xff0c;在短时间内测试代码中的处理逻辑。写好Java单元测试用例&#xff0c;其实就是把“复杂问题简单化&#xff0c;建单问题深入化“。在编写的…

Shell脚本练习——系统应用相关

显示系统信息 [rootwenzi data]#cat systemInfo.sh #/bin/bash RED"\E[1;31m" GREEN"\E[1;32m" END"\E[0m" echo -e "$GREEN----------------------Host systeminfo--------------------$END" echo -e "HOSTNAME: $REDho…