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}

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

轻量、便捷、高效—经纬恒润AETP助力车载以太网测试

随着自动驾驶技术和智能座舱的不断发展&#xff0c;高宽带、高速率的数据通信对主干网提出了稳定、高效的传输要求&#xff0c;CAN(FD)、LIN已无法充分满足汽车的通信需求。车载以太网作为一种快速且扩展性好的网络技术&#xff0c;已经逐步成为了汽车主干网的首选。 此外&…

Kubernetes技术--k8s核心技术 Secret

1.概述 Secret 解决了密码、token、密钥等敏感数据的配置问题,而不需要把这些敏感数据暴露到镜像或者 Pod Spec中。Secret可以以 Volume 或者环境变量的方式使用。 作用 加密数据存储在/etc中,使得pod容器以挂载volume方式进行访问。在进行的数据存储中是以base64加密的方式…

yolov2相较于yolov1的改进

目录 前言 BN层取代了Dropout 使用了高分辨率分类器 K-means选定先验框的尺寸 网络结构—darknet19 细粒度的特征 前言 yolov2是在yolov1的基础上进行改进的&#xff0c;主要解决了yolov1定位不准确以及检测重叠的物体极差的情况&#xff0c;总的来说&#xff0c;它有以下…

Gitee注册和使用

个人主页&#xff1a;点我进入主页 专栏分类&#xff1a;C语言初阶 C语言程序设计————KTV C语言小游戏 欢迎大家点赞&#xff0c;评论&#xff0c;收藏。 一起努力&#xff0c;一起奔赴大厂。 目录 1.Gitee 1.1Gitee是什么 1.2Gitee的注册以及远程仓库的创建…

iOS 设置下载部分文件,如何获取完整文件的大小

在视频的需求中&#xff0c;遇到这样一个需求&#xff0c;播放一视频的时候&#xff0c;要预下载 后面10条视频&#xff0c;但是只下载后面十条视频的前面1M 实现方法 1 创建请求时设置cacheLength resource [[IdiotResource alloc] init];resource.requestURL task.request…

docker命令学习

docker vscode插件出现的问题 docker命令 docker images &#xff08;查看所有的镜像&#xff09; docker ps -a &#xff08;查看所有的容器&#xff09; docker ps &#xff08;查看运行的容器&#xff09; docker run imageID docker run --gpus all --shm-size8g -it imag…

day27 String类 正则表达式

String类的getBytes方法 String s "腻害"; byte[] bytes s.getBytes(StandardCharsets.UTF_8); String类的new String方法 String ss "ss我的"; byte[] gbks ss.getBytes("gbk"); String gbk new String(gbks, "gbk"); String类的…

C++学习笔记总结练习:多态与虚函数

1 多态 多态分类 静态多态&#xff0c;是只在编译期间确定的多态。静态多态在编译期间&#xff0c;根据函数参数的个数和类型推断出调用的函数。静态多态有两种实现的方式 重载。&#xff08;函数重载&#xff09;模板。 动态多态&#xff0c;是运行时多态。通过虚函数机制实…

C#,《小白学程序》第八课:列表(List)应用之二“编制高铁列车时刻表”

1 文本格式 /// <summary> /// 车站信息类 class /// </summary> public class Station { /// <summary> /// 编号 /// </summary> public int Id { get; set; } 0; /// <summary> /// 车站名 /// </summary&g…

在Ubuntu Linux系统上安装RabbitMQ服务并解决公网远程访问问题

文章目录 前言1.安装erlang 语言2.安装rabbitMQ3. 内网穿透3.1 安装cpolar内网穿透(支持一键自动安装脚本)3.2 创建HTTP隧道 4. 公网远程连接5.固定公网TCP地址5.1 保留一个固定的公网TCP端口地址5.2 配置固定公网TCP端口地址 前言 RabbitMQ是一个在 AMQP(高级消息队列协议)基…

系列五、Java操作RocketMQ简单消息之同步消息

一、概述 同步消息的特征是消息发出后会有一个返回值&#xff0c;即RocketMQ服务器收到消息后的一个确认&#xff0c;这种方式非常安全&#xff0c;但是性能上却没有那么高&#xff0c;而且在集群模式下&#xff0c;也是要等到所有的从机都复制了消息以后才会返回&#xff0c;适…

QT(8.30)常用类与组件,实现登录界面

1.作业&#xff1a; 完成一个登录界面(图片未附带): 头文件: #ifndef WIDGET_H #define WIDGET_H#include <QWidget>#include <QLineEdit>//行编辑器#include<QIcon>//图标#include<QLabel>//标签#include<QPushButton>//按钮#include<QIc…

GA遗传算法

储备知识 GA算法主要解决数学模型中最优化的搜索算法&#xff0c;是进化算法中的一种&#xff0c;基因算法借鉴了自然界基因的遗传的主要现象&#xff0c;分别为遗传&#xff0c;变异&#xff0c;自然选择&#xff0c;杂交等。 GA算法参数 GA算法的参数如下所示。 种群规模…

JAVA 求最小公因数

JAVA 求最小公因数 文章目录 JAVA 求最小公因数方法一&#xff1a;枚举法的第一种方法一&#xff1a;枚举法的第二种方法二&#xff1a;展转相除法(欧几里德算法)方法三&#xff1a;递归拓展 求最小公倍数公式为综合 辗转相除法递归 求n个数的最大公约数和最小公倍数 题目&…

一百六十九、Hadoop——Hadoop退出NameNode安全模式与查看磁盘空间详情(踩坑,附截图)

一、目的 在海豚跑定时跑kettle的从Kafka到HDFS的任务时&#xff0c;由于Linux服务器的某个文件磁盘空间满了&#xff0c;导致Hadoop的NodeName进入安全模式&#xff0c;此时光执行hdfs dfsadmin -safemode leave命令语句没有效果&#xff08;虽然显示Safe mode is OFF&#x…

EFLK日志平台(filebeat-->kafka-->logstash-->es-->kiabana)

ELK平台是一套完整的日志集中处理解决方案&#xff0c;将 ElasticSearch、Logstash 和 Kiabana 三个开源工具配合使用&#xff0c; 完成更强大的用户对日志的查询、排序、统计需求。 安装顺序 1.安装es 7.17.12 2.安装kibana 7.17.12 3.安装x-pack 保证以上调试成功后开始下面…

C语言:动态内存(一篇拿捏动态内存!)

目录 学习目标&#xff1a; 为什么存在动态内存分配 动态内存函数&#xff1a; 1. malloc 和 free 2. calloc 3. realloc 常见的动态内存错误&#xff1a; 1. 对NULL指针的解引用操作 2. 对动态开辟空间的越界访问 3. 对非动态开辟内存使用free释放 4. 使用free释…

汽车自适应巡航系统控制策略研究

目 录 第一章 绪论 .............................................................................................................................. 1 1.1 研究背景及意义 ..........................................................................................…

Spring Boot 中 Nacos 配置中心使用实战

官方参考文档 https://nacos.io/zh-cn/docs/quick-start-spring-boot.html 本人实践 1、新建一个spring boot项目 我的spirngboot版本为2.5.6 2、添加一下依赖 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-…

【Locomotor运动模块】瞬移

文章目录 一、原理二、两种类型1、Instant(立刻)2、Dash&#xff08;猛冲&#xff09; 三、瞬移区域、瞬移点1、瞬移区域2、瞬移点 一、原理 抛物线指针选择好目标位置&#xff0c;然后告诉瞬移预设体&#xff1a;你想法把游戏区域弄到目标位置来 解释&#xff1a;抛物线指针选…