ChatGPT Prompting开发实战(三)

news2024/10/6 12:22:02

一、关于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.coloradmin.cn/o/952314.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

猜拳游戏小程序源码 大转盘积分游戏小程序源码 积分游戏小程序源码

简介&#xff1a; 猜拳游戏大转盘积分游戏小程序前端模板源码&#xff0c;一共五个静态页面&#xff0c;首页、任务列表、大转盘和猜拳等五个页面 图片&#xff1a;

计算数组中各元素的方差 忽略数组中所有的nan值 numpy.nanvar()

【小白从小学Python、C、Java】 【计算机等级考试500强双证书】 【Python-数据分析】 计算数组中各元素的方差 忽略数组中所有的nan值 numpy.nanvar() [太阳]选择题 请问关于以下代码最后输出结果的是&#xff1f; import numpy as np a np.array([1, np.nan, 3]) print("…

QT day1登录界面设计

要设计如下图片&#xff1a; 代码如下&#xff1a; main.cpp widget.h widget.cpp 运行效果&#xff1a; 2&#xff0c;思维导图

Mac下Docker Desktop安装命令行工具、开启本地远程访问

Mac系统下&#xff0c;为了方便在terminal和idea里使用docker&#xff0c;需要安装docker命令行工具&#xff0c;和开启Docker Desktop本地远程访问。 具体方法是在设置-高级下&#xff0c; 1.将勾选的User调整为System&#xff0c;这样不用手动配置PATH即可使用docker命令 …

Windows部署ftp

Windows部署ftp 小白教程&#xff0c;一看就会&#xff0c;一做就成。 1.安装包&#xff0c;需要的可以滴滴我 2.部署 就修改下面标注的&#xff0c;别的可以不动 如果想要多个用户&#xff0c;复制这些&#xff0c;把名字&#xff0c;密码改改就行 端口 启动 cmd窗口不要关闭…

sv断言积累

基本概念&#xff1a; ​​​​​​​​​​​​​​​​​​​​​https://www.cnblogs.com/lyc-seu/p/12718412.htmlhttps://www.cnblogs.com/lyc-seu/p/12718412.html 波形查看&#xff1a; 断言波形显示_波形中看断言_风起云涌66的博客-CSDN博客文章目录一、为何要在波形…

详解 Vue 3 使用了 Proxy 对象来替代 Vue 2 中的 Object.defineProperty

在 Vue 2 中&#xff0c;响应式系统使用了 Object.defineProperty 来实现属性的劫持和监听。这种方式需要在对象上定义 getter 和 setter&#xff0c;以便在属性被访问或修改时触发相应的操作。 然而&#xff0c;Object.defineProperty 有一些限制和性能问题。它只能劫持对象的…

华为云软件精英实战营——感受软件改变世界,享受Coding乐趣

机器人已经在诸多领域显现出巨大的商业价值&#xff0c;华为云计算致力于以云助端的方式为机器人产业带来全新机会 如果您是开发爱好者&#xff0c;想了解华为云&#xff0c;想和其他自由开发者交流经验&#xff1b; 如果您是学生&#xff0c;想和正在从事软件开发行业的大佬…

5G工业网关赋能救护车远程监控,助力高效救援

智慧医疗是传统医疗业发展进步的必要趋势&#xff0c;医疗设备通过物联网技术的应用实现智能化转型。通过5G工业网关将医疗器械等设备的数据采集再经过专网传输到医疗系统中&#xff0c;实现医疗设备间的数据共享和远程监控&#xff0c;能够帮助医疗行业大大提高服务质量和管理…

如何在B站进行学习直播

诸神缄默不语-个人CSDN博文目录 会根据我使用的情况进行持续更新 文章目录 1. 电脑 - 哔哩哔哩直播姬1. 软件的基础使用2. 素材1. 摄像头2. 窗口捕捉3. 游戏进程图片文字浏览器 3. H5插件其他注意事项 2. 手机直播3. iPad直播 1. 电脑 - 哔哩哔哩直播姬 1. 软件的基础使用 电…

css让元素保持等比例宽高

使用新属性 aspect-ratio: 16/9; 代码示例 <style>div {width: 60%;/* 等比例宽高 */aspect-ratio: 16/9;background-color: red;margin: auto;}</style> </head><body><div></div> </body>示例 aspect-ratio兼容性

transformer实现词性标注

1、self-attention 1.1、self-attention结构图 上图是 Self-Attention 的结构&#xff0c;在计算的时候需要用到矩阵 Q(查询), K(键值), V(值)。在实际中&#xff0c;Self-Attention 接收的是输入(单词的表示向量 x组成的矩阵 X) 或者上一个 Encoder block 的输出。而 Q, K, V…

什么是跨域(cross-origin)请求,如何解决跨域问题?

聚沙成塔每天进步一点点 ⭐ 专栏简介⭐ 跨域请求和跨域问题⭐ 解决跨域问题的方法1. CORS&#xff08;跨域资源共享&#xff09;2. JSONP&#xff08;JSON with Padding&#xff09;3. 代理服务器4. WebSocket5. 使用服务器中继 ⭐ 写在最后 ⭐ 专栏简介 前端入门之旅&#xff…

[C++]构造与毁灭:深入探讨C++中四种构造函数与析构函数

个人主页&#xff1a;北海 &#x1f390;CSDN新晋作者 &#x1f389;欢迎 &#x1f44d;点赞✍评论⭐收藏✨收录专栏&#xff1a;C/C&#x1f91d;希望作者的文章能对你有所帮助&#xff0c;有不足的地方请在评论区留言指正&#xff0c;大家一起学习交流&#xff01;&#x1f9…

ModaHub魔搭社区:星环科技致力于打造更优越的向量数据库

在数字化时代,数据成为了最重要的资源之一。随着人工智能、大数据等技术的不断发展,向量数据库成为了处理这类数据的关键工具。星环科技作为一家专注于数据存储和管理技术的公司,其重要目标就是将向量数据库打造得更为优越。 在星环科技,有一个专注于向量数据库的团队。这个…

当面试遇到难题:解决棘手问题的三大策略

&#x1f337;&#x1f341; 博主猫头虎 带您 Go to New World.✨&#x1f341; &#x1f984; 博客首页——猫头虎的博客&#x1f390; &#x1f433;《面试题大全专栏》 文章图文并茂&#x1f995;生动形象&#x1f996;简单易学&#xff01;欢迎大家来踩踩~&#x1f33a; &a…

【C++】关于fixed和setprecision的学习和介绍

前言 在学习swap函数的时候&#xff0c;偶然了解到了fixed和setprecision&#xff0c;这两条控制语句&#xff0c;在了解了之后&#xff0c;觉得很有用&#xff0c;于是写一篇文章来介绍fixed和setprecision这两条控制语句 fixed控制输出形式 使用fixed语句需要包含<ioma…

Python2021年06月Python二级 -- 编程题解析

题目一 没有重复数字的两位数统计 编写一段程序&#xff0c;实现下面的功能: (1)检查所有的两位数; (2)程序自动分析两位数上的个位与十位上的数字是否相同&#xff0c;相同则剔除&#xff0c; 不同则保留(例:12符合本要求&#xff0c;个位是2&#xff0c;十位是1&#xff0c;两…

第7节——渲染列表+Key作用

一、列表渲染 我们再react中如果渲染列表&#xff0c;一般使用map方法进行渲染 import React from "react";export default class LearnJSX2 extends React.Component {state {infos: [{name: "张三",age: 18,},{name: "李四",age: 20,},{nam…

C#,数值计算——Midexp的计算方法与源程序

1 文本格式 using System; namespace Legalsoft.Truffer { public class Midexp : Midpnt { public new double func(double x) { return funk.funk(-Math.Log(x)) / x; } public Midexp(UniVarRealValueFun funcc, double aa, d…