OpenAI官方吴达恩《ChatGPT Prompt Engineering 提示词工程师》(2)如何迭代开发提示词

迭代/Iterative


在机器学习中,您经常有一个想法,然后实现它。编写代码,获取数据,训练模型,这就给您一个实验结果。然后您可以查看该输出,进行错误分析,找出哪些地方工作或不工作,然后甚至可以改变您要解决的问题或如何处理它的确切想法,并更改实现并运行另一个实验等,一遍又一遍地迭代,以获得有效的机器学习模型。
在写prompt提示词的时候,该过程可能非常相似,您可以有一个关于您想要完成的任务的想法,然后尝试编写第一个提示,希望它清晰具体,并可能在适当的情况下给系统一些时间来思考,然后运行它并查看结果。

  • Be clear and specific
  • Analyze why result does not give desired output.
  • Refine the idea and the prompt
  • Repeat

Iterative Process

  • Try something
  • Analyze where the result does not give what you want
  • Clarify instructions, give more time to think 澄清您的指令,或者在某些情况下,考虑给它更多的思考空间,以使其更接近于产生您想要的结果。
  • Refine prompts with a batch of examples对多个示例进行提示评估可能是有用的,以查看平均或最差情况的性能如何

环境准备

和上文内容(①指南)一样进行环境的准备,获取openAI秘钥。

import openai
import osfrom dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv()) # read local .env fileopenai.api_key  = os.getenv('OPENAI_API_KEY')
def get_completion(prompt, model="gpt-3.5-turbo"):messages = [{"role": "user", "content": prompt}]response = openai.ChatCompletion.create(model=model,messages=messages,temperature=0, # this is the degree of randomness of the model's output)return response.choices[0].message["content"]

案例:生成产品描述

这是一个椅子的事实表,其中描述了它是一个美丽的中世纪灵感家族的一部分,讲述了构造,尺寸,椅子选项,材料等。它来自意大利。所以,假设您想要将这个事实表提供给营销团队,以帮助他们为在线零售网站撰写描述。

fact_sheet_chair = """
OVERVIEW
- Part of a beautiful family of mid-century inspired office furniture, 
including filing cabinets, desks, bookcases, meeting tables, and more.
- Several options of shell color and base finishes.
- Available with plastic back and front upholstery (SWC-100) 
or full upholstery (SWC-110) in 10 fabric and 6 leather options.
- Base finish options are: stainless steel, matte black, 
gloss white, or chrome.
- Chair is available with or without armrests.
- Suitable for home or business settings.
- Qualified for contract use.CONSTRUCTION
- 5-wheel plastic coated aluminum base.
- Pneumatic chair adjust for easy raise/lower action.DIMENSIONS
- WIDTH 53 CM | 20.87”
- DEPTH 51 CM | 20.08”
- HEIGHT 80 CM | 31.50”
- SEAT HEIGHT 44 CM | 17.32”
- SEAT DEPTH 41 CM | 16.14”OPTIONS
- Soft or hard-floor caster options.
- Two choices of seat foam densities: medium (1.8 lb/ft3) or high (2.8 lb/ft3)
- Armless or 8 position PU armrests MATERIALS
SHELL BASE GLIDER
- Cast Aluminum with modified nylon PA6/PA66 coating.
- Shell thickness: 10 mm.
SEAT
- HD36 foamCOUNTRY OF ORIGIN
- Italy
"""

我的提示是:您的任务是帮助营销团队基于技术事实表为零售网站或产品创建描述,编写产品描述等。


Python
prompt = f"""
Your task is to help a marketing team create a 
description for a retail website of a product based 
on a technical fact sheet.Write a product description based on the information 
provided in the technical specifications delimited by 
triple backticks.Technical specifications: ```{fact_sheet_chair}```
"""
response = get_completion(prompt)
print(response)
"""
Introducing our stunning mid-century inspired office chair, the perfect addition to any home or business setting. Part of a beautiful family of office furniture, including filing cabinets, desks, bookcases, meeting tables, and more, this chair is available in several options of shell color and base finishes to suit your style. Choose from plastic back and front upholstery (SWC-100) or full upholstery (SWC-110) in 10 fabric and 6 leather options.The chair is constructed with a 5-wheel plastic coated aluminum base and features a pneumatic chair adjust for easy raise/lower action. It is available with or without armrests and is qualified for contract use. The base finish options are stainless steel, matte black, gloss white, or chrome.Measuring at a width of 53 cm, depth of 51 cm, and height of 80 cm, with a seat height of 44 cm and seat depth of 41 cm, this chair is designed for ultimate comfort. You can also choose between soft or hard-floor caster options and two choices of seat foam densities: medium (1.8 lb/ft3) or high (2.8 lb/ft3). The armrests are available in either an armless or 8 position PU option.The materials used in the construction of this chair are of the highest quality. The shell base glider is made of cast aluminum with modified nylon PA6/PA66 coating and has a shell thickness of 10 mm. The seat is made of HD36 foam, ensuring maximum comfort and durability.This chair is made in Italy and is the perfect combination of style and functionality. Upgrade your workspace with our mid-century inspired office chair today!
"""

1、修改输出字数

修改提示:使用最多50个单词来更好地指导所需长度

prompt = f"""
Your task is to help a marketing team create a 
description for a retail website of a product based 
on a technical fact sheet.Write a product description based on the information 
provided in the technical specifications delimited by 
triple backticks.Use at most 50 words. #修改提示
#Use at most 280 charact 
#Use at most 3 sentences.Technical specifications: ``{fact_sheet_chair}``
"""
response = get_completion(prompt)
print(response)
...
Introducing our mid-century inspired office chair, part of a beautiful furniture family. Available in various shell colors and base finishes, with plastic or full upholstery options in fabric or leather. Suitable for home or business use, with a 5-wheel base and pneumatic chair adjust. Made in Italy.
...

2、修改面向用户

这个描述不是直接销售给消费者,而是旨在向家具零售商销售家具,因此应该是技术性的,重点放在材料、产品和构造方面。

prompt = f"""
Your task is to help a marketing team create a 
description for a retail website of a product based 
on a technical fact sheet.Write a product description based on the information 
provided in the technical specifications delimited by 
triple backticks.#以下是添加的描述
The description is intended for furniture retailers, 
so should be technical in nature and focus on the 
materials the product is constructed from.Use at most 50 words.Technical specifications: ``{fact_sheet_chair}``
"""
response = get_completion(prompt)
print(response)
"""
Introducing our mid-century inspired office chair, perfect for both home and business settings. With a range of shell colors and base finishes, including stainless steel and matte black, this chair is available with or without armrests. The 5-wheel plastic coated aluminum base and pneumatic chair adjust make it easy to move and adjust to your desired height. Made with high-quality materials, including a cast aluminum shell and HD36 foam seat, this chair is built to last.
"""

在描述的结尾处,我还想包括产品ID。包括每个7个字符的产品ID。

prompt = f"""
Your task is to help a marketing team create a 
description for a retail website of a product based 
on a technical fact sheet.Write a product description based on the information 
provided in the technical specifications delimited by 
triple backticks.The description is intended for furniture retailers, 
so should be technical in nature and focus on the 
materials the product is constructed from.At the end of the description, include every 7-character 
Product ID in the technical specification.Use at most 50 words.Technical specifications: ``{fact_sheet_chair}``
"""
response = get_completion(prompt)
print(response)
"""
chair, perfect for home or business settings. With a range of shell colors and base finishes, and the option of plastic or full upholstery, this chair is both stylish and comfortable. Constructed with a 5-wheel plastic coated aluminum base and pneumatic chair adjust, it's also practical. Available with or without armrests and suitable for contract use. Product ID: SWC-100, SWC-110.
"""

3、表格输出

给出产品尺寸的表格,然后将所有内容格式化为HTML

prompt = f"""
Your task is to help a marketing team create a 
description for a retail website of a product based 
on a technical fact sheet.Write a product description based on the information 
provided in the technical specifications delimited by 
triple backticks.The description is intended for furniture retailers, 
so should be technical in nature and focus on the 
materials the product is constructed from.#以下是新增的提示词
At the end of the description, include every 7-character 
Product ID in the technical specification.Use at most 50 words.Technical specifications: ``{fact_sheet_chair}``
"""
response = get_completion(prompt)
print(response)
"""
<div>
<h2>Mid-Century Inspired Office Chair</h2>
<p>Introducing our mid-century inspired office chair, part of a beautiful family of office furniture that includes filing cabinets, desks, bookcases, meeting tables, and more. This chair is available in several options of shell color and base finishes, allowing you to customize it to your liking. You can choose between plastic back and front upholstery or full upholstery in 10 fabric and 6 leather options. The base finish options are stainless steel, matte black, gloss white, or chrome. The chair is also available with or without armrests, making it suitable for both home and business settings. Plus, it's qualified for contract use, ensuring its durability and longevity.</p>
<p>The chair's construction features a 5-wheel plastic coated aluminum base and a pneumatic chair adjust for easy raise/lower action. You can also choose between soft or hard-floor caster options and two choices of seat foam densities: medium (1.8 lb/ft3) or high (2.8 lb/ft3). The armrests are also customizable, with the option of armless or 8 position PU armrests.</p>
<p>The materials used in the chair's construction are of the highest quality. The shell base glider is made of cast aluminum with modified nylon PA6/PA66 coating, with a shell thickness of 10 mm. The seat is made of HD36 foam, ensuring maximum comfort and support.</p>
<p>Made in Italy, this mid-century inspired office chair is the perfect addition to any office space. Order yours today!</p>
<h3>Product IDs:</h3>
<ul>
<li>SWC-100</li>
<li>SWC-110</li>
</ul>
</div><table><caption>Product Dimensions</caption><tr><th>Dimension</th><th>Measurement (inches)</th></tr><tr><td>Width</td><td>20.87"</td></tr><tr><td>Depth</td><td>20.08"</td></tr><tr><td>Height</td><td>31.50"</td></tr><tr><td>Seat Height</td><td>17.32"</td></tr><tr><td>Seat Depth</td><td>16.14"</td></tr>
</table>
"""

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

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

相关文章

郁金香2021年游戏辅助技术(初级班)(上)

郁金香2021年游戏辅助技术初级班&#xff08;上&#xff09; %p、size_t、%zd、%llu、FindWindow、GetWindowText、SetWindowTextGetWindowThreadProcessId、OpenProcess、ReadProcessMemory封接读内存接口函数 int R4(void* 地址)跨进程向目标进程内存地址写入数值 WriteProce…

【每日一题】递枕头

文章目录 Tag题目来源题目解读解题思路方法一&#xff1a;模拟方法二&#xff1a; O ( 1 ) O(1) O(1) 解法 写在最后 Tag 【模拟】【 O ( 1 ) O(1) O(1) 公式】【2023-09-26】 题目来源 2582. 递枕头 题目解读 编号从 1 到 n 的 n 个人站成一排传递枕头。最初&#xff0c;排…

华南理工大学电子与信息学院23年预推免复试面试经验贴

运气较好&#xff0c;复试分数90.24&#xff0c;电科学硕分数线84、信通83、专硕电子与信息74. 面试流程&#xff1a; 1&#xff1a;5min ppt的介绍。其中前2min用英语简要介绍基本信息&#xff0c;后3min可用英语也可用中文 介绍具体项目信息如大创、科研、竞赛等&#xff08…

出现 conda虚拟环境默认放在C盘 解决方法

目录 1. 问题所示2. 原理分析3. 解决方法3.1 方法一3.2 方法二1. 问题所示 通过conda配置虚拟环境的时候,由于安装在D盘下,但是配置的环境默认都给我放C盘 通过如下命令:conda env list,最后查看该环境的确在C盘下 2. 原理分析 究其根本原因,这是因为默认路径没有足够的…

编程每日一练(多语言实现):判断偶数

文章目录 一、实例描述二、技术要点三、代码实现3.1 C 语言实现3.2 Python 语言实现3.3 Java 语言实现 一、实例描述 利用单条件单分支选择语句判断输入的一个整数 是否是偶数。 运行程序&#xff0c;输入一个 整数18&#xff0c; 然后按回车键&#xff0c;将提示该数字是偶数…

linux使用操作[2]

文章目录 版权声明网络传输ping命令wget命令curl命令端口linux端口端口命令和工具 进程管理查看进程关闭进程 主机状态top命令内容详解磁盘信息监控 版权声明 本博客的内容基于我个人学习黑马程序员课程的学习笔记整理而成。我特此声明&#xff0c;所有版权属于黑马程序员或相…

Android ConstraintLayout app:layout_constraintHorizontal_weight

Android ConstraintLayout app:layout_constraintHorizontal_weight <?xml version"1.0" encoding"utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android"http://schemas.android.com/apk/res/android"xmlns:…

【已解决】qt死活不响应鼠标移动到按钮事件

本博文源于笔者正在研究的内容&#xff0c;这个问题大概捣鼓了一个下午&#xff0c;问题是这样子&#xff1a;我有一个按钮&#xff0c;我应用程序运行时&#xff0c;我鼠标放到按钮上&#xff0c;按钮就会被填充图标。怀揣着这样一个想法&#xff0c;我搜啊搜&#xff0c;整啊…

verilog学习笔记(1)module实例化2

移位寄存器多路选择器 我的代码&#xff1a; module top_module ( input clk, input [7:0] d, input [1:0] sel, output [7:0] q );wire [7:0] w1;wire [7:0] w2;wire [7:0] w3;my_dff8 my_dff8_1(.clk(clk),.d(d),.q(w1));my_dff8 my_dff8_2(.clk(clk),.d(w1),.q(w2));my_d…

前端知识总结

在前端开发中&#xff0c;y x是一种常见的自增运算符的使用方式。它表示将变量x的值自增1&#xff0c;并将自增后的值赋给变量y。 具体来说&#xff0c;x是一种后缀自增运算符&#xff0c;表示将变量x的值自增1。而y x则是将自增前的值赋给变量y。这意味着在执行y x之后&am…

【MySQL】表的约束

文章目录 1. 表的约束概述2. 空属性 not null3. 默认值 default4. 列描述 comment5. zerofill6. 主键 primary key7. 自增长 auto_increment8. 唯一键 unique9. 外键 foreign key 1. 表的约束概述 真正约束字段的是数据类型&#xff0c;但是数据类型约束很单一&#xff0c;需要…

基于微信小程序的英语互助小程序设计与实现(亮点:小组制打卡、模拟考试答题、错题本、学习论坛)

文章目录 前言系统主要功能&#xff1a;具体实现截图论文参考详细视频演示为什么选择我自己的网站自己的小程序&#xff08;小蔡coding&#xff09;有保障的售后福利 代码参考源码获取 前言 &#x1f497;博主介绍&#xff1a;✌全网粉丝10W,CSDN特邀作者、博客专家、CSDN新星计…

什么是 AirServer?Mac专用投屏工具AirServer 7 .27 for Mac中文破解版百度网盘下载

AirServer 7 .27 for Mac中文免费激活版是一款Mac专用投屏工具&#xff0c;能够通过本地网络将音频、照片、视频以及支持AirPlay功能的第三方App&#xff0c;从 iOS 设备无线传送到 Mac 电脑的屏幕上&#xff0c;把Mac变成一个AirPlay终端的实用工具。 目前最新的AirServer 7.2…

从零开始—【Mac系统】MacOS配置Java环境变量

系统环境说明 Apple M1 macOS Ventura 版本13.5.2 1.下载JDK安装包 Oracle官网下载地址 JDK下载【注&#xff1a;推荐下载JDK8 Oracle官网JDK8下载】 关于JDK、JRE、JVM的关系说明 JDK(Java Development Kit&#xff0c;Java开发工具包) &#xff0c;是整个JAVA的核心&#…

ctfshow web入门(21-28爆破)

web21 抓包 进行了base64加密&#xff0c;解码后发现账号和密码格式是 账号:密码 爆破 位置一开始选错了&#xff0c;应该是不含Basic的 模式选择custom iterator(自定义迭代器) 自定义迭代器可以自定义拼接方式 分别设置三个位置&#xff0c;第一个位置为admin 第二个位置…

RHCE---Linux的计划任务

文章目录 目录 文章目录 前言 一.单一执行的例行性工作 at 命令 二.循环执行的例行性工作 crontab 命令 课后作业&#xff1a; 思维导图 前言 如果想要让自己设计的备份程序可以自动地在系统下面运行&#xff0c;而不需要手动来启动它&#xff0c;这是该如何处理&#xff1f…

威胁追踪如何增强您的网络安全态势

网络威胁的复杂性、频率和影响正在加剧。2022 年&#xff0c;勒索软件攻击达到2.361 亿次&#xff0c;其中 39% 的英国企业遭受网络攻击。 这些攻击需要工具和资源来识别和纠正漏洞&#xff0c;以在云环境中维护强大的安全框架&#xff0c;从而降低数据泄露和合规违规的风险。…

asp.net core automapper的使用

1.安装automapper的nuget包 AutoMapper.Extensions.Microsoft.DependencyInjection 2.创建需要映射的类和转换后的类 public class studto{public int sn { get; set; }public string name { get; set; }public string sex { get; set; }public int age { get; set; }public s…

mac 配置 httpd nginx php-fpm 详细记录 已解决

在日常mac电脑 开发php项目一直是 httpd 方式 运行&#xff0c;由于有 多版本 运行的需求&#xff0c;docker不想用&#xff0c;索性用 php-fpm进行 功能处理。上次配置 是好的&#xff0c;但是感觉马马虎虎&#xff0c;这次 配置底朝天。因为配置服务器&#xff0c;几乎也都是…

List<HashMap<String,String>>实现自定义字符串排序(key排序、Value排序)

系列文章目录 SpringBootVue3实现登录验证码功能 Java实现发送邮件&#xff08;定时自动发送邮件&#xff09; 换个角度使用Redis去解决跨域存取Session问题 Redis缓存穿透、击穿、雪崩问题及解决方法 Spring Cache的使用–快速上手篇 更多该系列文章请查看我的主页哦 文章目录…