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.mzph.cn/news/65185.shtml

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

相关文章

如何制作并运行 jar 程序

以下是用 Intellij 制作 jar 程序&#xff0c;并运行的方法。 【1】新建工程&#xff0c;保持默认选项&#xff0c;Next 【2】保持默认选项&#xff0c;Next 【3】给工程命名&#xff0c;设置保存位置&#xff0c;Finish 【4】新建工程结束&#xff0c;进入开发界面 【5】展开…

Redis图文指南

1、什么是 Redis&#xff1f; Redis&#xff08;REmote DIctionary Service&#xff09;是一个开源的键值对数据库服务器。 Redis 更准确的描述是一个数据结构服务器。Redis 的这种特殊性质让它在开发人员中很受欢迎。 Redis不是通过迭代或者排序方式处理数据&#xff0c;而是…

Oracle21C--Windows卸载与安装

卸载方法&#xff1a; &#xff08;1&#xff09;WinR&#xff0c;输入services.msc,打开服务&#xff0c;把Oracle相关的服务全部停止运行&#xff08;重要&#xff09; &#xff08;2&#xff09;WinR&#xff0c;输入regedit&#xff0c;打开注册表&#xff0c;删除Oracle开…

无涯教程-Android - CheckBox函数

CheckBox是可以由用户切换的on/off开关。为用户提供一组互不排斥的可选选项时,应使用复选框。 CheckBox 复选框属性 以下是与CheckBox控件相关的重要属性。您可以查看Android官方文档以获取属性的完整列表以及可以在运行时更改这些属性的相关方法。 继承自 android.widget.T…

肖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; 第一行&…

19 Linux之Python定制篇-apt软件管理和远程登录

19 Linux之Python定制篇-apt软件管理和远程登录 文章目录 19 Linux之Python定制篇-apt软件管理和远程登录19.1 apt软件管理19.1.1 apt介绍19.1.2 更新软件下载地址-阿里源19.1.3 使用apt完成安装和卸载vim 19.2 远程登录Ubuntu 学习视频来自于B站【小白入门 通俗易懂】2021韩顺…

Linux x86_64 C语言实现gdb断点机制

文章目录 前言一、trap指令简介二、调用ptrace三、创建breakpoints四、CONT 和 SINGLESTEP五、完整代码演示六、增加参数检测参考资料 前言 本文参考文章&#xff1a;Implementing breakpoints on x86 Linux 一、trap指令简介 将通过在断点地址向目标进程的内存中插入一条新…

面试中的商业思维:如何展示你对业务的理解

&#x1f337;&#x1f341; 博主猫头虎&#xff08;&#x1f405;&#x1f43e;&#xff09;带您 Go to New World✨&#x1f341; &#x1f984; 博客首页——&#x1f405;&#x1f43e;猫头虎的博客&#x1f390; &#x1f433; 《面试题大全专栏》 &#x1f995; 文章图文…

SourceTree 使用技巧

参考资料 SourceTree使用教程&#xff08;一&#xff09;—克隆、提交、推送SourceTree的软合并、混合合并、强合并区别SourceTree 合并分支上的多个提交&#xff0c;一次性合并分支的多次提交至另一分支&#xff0c;主分支前进时的合并冲突解决 目录 一. 基础设置1.1 用户信息…

VR司法法治教育平台,沉浸式课堂教学培养刑侦思维和能力

VR司法法治教育平台提供了多种沉浸式体验&#xff0c;通过虚拟现实(Virtual Reality&#xff0c;简称VR)技术让用户深度参与和体验法治知识。以下是一些常见的沉浸式体验&#xff1a; 1.罪案重现 VR司法法治教育平台可以通过重现真实案例的方式&#xff0c;让用户亲眼目睹罪案发…

一文了解气象站是什么,作用有哪些?

气象站被广泛应用于气象、农业、交通、能源、水利、环保等领域&#xff0c;是一种用于收集、分析和处理气象数据的设备&#xff0c;能够为人们提供及时、准确的气象数据和决策支持。 气象站一般由传感器、环境监控主机和监控平台组成。传感器能够测量各种气象要素&#xff0c;…

Spring 中存取 Bean 的相关注解

目录 一、五大类注解 1、五大类注解存储Bean对象 1.1Controller(控制器储存) 1.2Service(服务存储) 1.3Repository(仓库存储) 1.4Component(组件存储) 1.5Configuration(配置存储) 2、五大类注解小结 2.1为什么要这么多类注解 2.2 五大类注解之间的关系 二、方法注解 1.方法注…

SQL-子查询

SQL 子查询 是指将一个SELECT查询&#xff08;子查询&#xff09;的结果用括号括起来作为另一个SQL语句的数据来源或者判断条件

【Bug】Ubuntu 有线设置打不开无反应

前言&#xff1a; 突然有线设置就没法启用了&#xff0c;但是能联网&#xff0c;能查看ip 解决&#xff1a; 最后安装了一个新的依赖包&#xff1a; sudo apt install gnome-control-center 然后就可以了 还有一个方法&#xff0c;没试过&#xff0c;但感觉有点道理的&#…

在抖音中使用语聚AI,实现自动回复用户视频评论、私信问答

您可以通过集简云数据流程&#xff0c;将语聚AI助手集成到抖音视频评论、抖音私信&#xff0c;实现自动回复用户视频评论、私信问答&#xff0c;大大提升账号互动与运营效率。 效果如下&#xff1a; 自动化流程&#xff1a; ● 抖音普通号评论对接语聚AI&#xff08;点击可一…

宏观经济和风电预测误差分析(Matlab代码实现)

&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜密&#xff0c;逻辑清晰&#xff0c;为了方便读者。 ⛳️座右铭&a…

pytorch异常——RuntimeError:Given groups=1, weight of size..., expected of...

文章目录 省流异常报错异常截图异常代码原因解释修正代码执行结果 省流 nn.Conv2d 需要的输入张量格式为 (batch_size, channels, height, width)&#xff0c;但您的示例输入张量 x 是 (batch_size, height, width, channels)。因此&#xff0c;需要对输入张量进行转置。 注意…

LLM学习笔记(1)

学习链接 ChatGPT Prompt Engineering for Developers - DeepLearning.AI 一、prompt engineering for developer 1、原则 prompting principles and iterative pattern 2、用于summarize 环境与helper functions import openai import osfrom dotenv import load_dotenv…

[C++] STL_list常用接口的模拟实现

文章目录 1、list的介绍与使用1.1 list的介绍1.2 list的使用 2、list迭代器3、list的构造4、list常用接口的实现4.1 list capacity4.2 插入删除、交换、清理4.2.1 insert任意位置插入4.2.2 push_front头插4.2.3 push_back尾插4.2.4 erase任意位置删除4.2.5 pop_front头删4.2.6 …

Redis之管道解读

目录 基本介绍 使用例子 管道对比 管道与原生批量命令对比 管道与事务对比 使用pipeline注意事项 基准测试 基本介绍 Redis是一种基于客户端-服务端模型以及请求/响应协议的TCP服务器。 这意味着请求通常按如下步骤处理&#xff1a; 客户端发送一个请求到服务器&am…