吴恩达prompt 笔记2:迭代提示开发(Iterative Prompt Develelopment)

1 前言 

  • 我们很难在初次尝试中就设计出最佳的提示,因此需要根据ChatGPT的反馈进行分析,分析输出具体在哪里不符合期望,然后不断思考和优化提示。
  • 如果有条件的话,最好是利用批量的样本来改善提示,这样可以对你的优化结果有一个较为直观的体现。

准备代码和之前的一样,就不加注释了,详情见: 大模型笔记:吴恩达 ChatGPT Prompt Engineering for Developers(1) prompt的基本原则和策略-CSDN博客

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"]

2 举例:根据货物单,生成一个货品描述

2.0 货物单:

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
"""

2.1 prompt 版本1

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 the SWC-100/SWC-110 Office Chair, a sleek and stylish addition to any workspace. This chair is part of a stunning collection of mid-century inspired office furniture, offering a cohesive look with filing cabinets, desks, bookcases, meeting tables, and more.Customize your chair with several options for shell color and base finishes to suit your personal style. Choose between plastic back and front upholstery or full upholstery in a variety of fabric and leather options. The base finish options include stainless steel, matte black, gloss white, or chrome, allowing you to create the perfect look for your space.Designed for both home and business settings, this chair is suitable for contract use and offers comfort and functionality. The 5-wheel plastic coated aluminum base provides stability, while the pneumatic chair adjust allows for easy raise/lower action.With dimensions of 53 cm in width, 51 cm in depth, and 80 cm in height, this chair offers a comfortable seat height of 44 cm and seat depth of 41 cm. Choose between soft or hard-floor caster options and two seat foam densities for personalized comfort. The chair is available with or without armrests, with the option for 8 position PU armrests.Constructed with high-quality materials, including a cast aluminum shell with modified nylon coating and HD36 foam seat, this chair is both durable and stylish. Made in Italy, you can trust in the craftsmanship and design of this office chair.Elevate your workspace with the SWC-100/SWC-110 Office Chair, a versatile and sophisticated seating solution for any environment.
'''

2.2 prompt 版本2:限制 生成文本的长度

+ Use at most 50 words.

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.Technical specifications: ```{fact_sheet_chair}```
"""
response = get_completion(prompt)
print(response)
'''
Introducing our versatile and stylish office chair, part of amid-century inspired furniture collection. Available in various 
colors and finishes, with customizable upholstery options.Designed for comfort and durability, suitable for both home 
and business use. Made in Italy with high-quality materials. 
Elevate your workspace with this modern chair.
'''len(response.split()) #49

2.3 prompt 版本3:着重在听众需要的信息上

+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.

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)
'''
Introducing our versatile office chair, part of a stylish mid-century 
inspired collection. Choose from a variety of shell colors and base 
finishes to suit your space. Constructed with a durable aluminum base 
and high-density foam seat for comfort. Perfect for home or office use. 
Product IDs: SWC-100, SWC-110.
'''

2.4 prompt 版本4:添加产品各维度数据的表格

+After the description, include a table that gives the  product's dimensions. The table should have two columns. In the first column include the name of the dimension.  In the second column include the measurements in inches only.

+Give the table the title 'Product Dimensions'.

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.After the description, include a table that gives the 
product's dimensions. The table should have two columns.
In the first column include the name of the dimension. 
In the second column include the measurements in inches only.Give the table the title 'Product Dimensions'.Use at most 50 words.Technical specifications: ```{fact_sheet_chair}```
"""response = get_completion(prompt)
print(response)
'''
Introducing our versatile and stylish office chair, part of a 
mid-century inspired furniture collection. Constructed with a 
durable cast aluminum shell and base glider coated with modified 
nylon. The seat features high-density foam for comfort. Available 
in various colors and finishes. Perfect for home or office use. Product IDs: SWC-100, SWC-110Product Dimensions:
| Dimension    | Measurement |
|--------------|-------------|
| Width        | 20.87"      |
| Depth        | 20.08"      |
| Height       | 31.50"      |
| Seat Height  | 17.32"      |
| Seat Depth   | 16.14"      |Shop now and elevate your workspace with this Italian-made chair.
'''

2.5 prompt 版本5:输出内容改成HTML格式

+Format everything as HTML that can be used in a website.  Place the description in a <div> element.

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.After the description, include a table that gives the 
product's dimensions. The table should have two columns.
In the first column include the name of the dimension. 
In the second column include the measurements in inches only.Give the table the title 'Product Dimensions'.Format everything as HTML that can be used in a website. 
Place the description in a <div> element.Technical specifications: ```{fact_sheet_chair}```
"""response = get_completion(prompt)
print(response)
'''
<div>
<p>This mid-century inspired office chair is a stylish and functional 
addition to any workspace. The chair is available in a variety of shell 
colors and base finishes to suit your aesthetic preferences. You can 
choose between plastic back and front upholstery or full upholstery in 
a range of fabric and leather options. The chair is constructed with a 
durable 5-wheel plastic coated aluminum base and features a pneumatic 
adjust for easy height customization. Whether you need a chair for your 
home office or a business setting, this chair is a versatile and comfortable 
choice. Made in Italy, this chair is designed for both style and durability.</p><p>Product IDs: SWC-100, SWC-110</p><table><caption>Product Dimensions</caption><tr><th>Dimension</th><th>Measurements (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>
</div>
'''

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

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

相关文章

Spring炼气之路(炼气一层)

目录 一、IOC 1.1 控制反转是什么&#xff1f; 1.2 什么是IOC容器&#xff1f; 1.3 IOC容器的作用 1.4 IOC容器存放的是什么&#xff1f; 二、DI 2.1 依赖注入是什么&#xff1f; 2.2 依赖注入的作用 三、IOC案例实现 3.1下载Maven 3.2 配置Maven中的settings.xml文…

【经验总结】ubuntu 20.04 git 上传本地文件给 github,并解决出现的问题

1. 在GitHub 上创建仓库 登录 GitHub 个人网站 点击 New 填写 Repository name, 以及 Description (optional) 选择 Public &#xff0c; 并添加 Add a README file 点击 Create repository github repository 创建成功 2. 设置SSH key 在本地 bash 运行&#xff1a;…

【PLC】现场总线和工业以太网汇总

1、 现场总线 1.1 什么是现场总线 1&#xff09;非专业描述&#xff1a; 如下图&#xff1a;“人机界面”一般通过以太网连接“控制器(PLC)”&#xff0c;“控制器(PLC)”通过 “现场总线”和现场设备连接。 2&#xff09;专业描述&#xff08;维基百科&#xff09; 现场总线…

WAAP全站防护是什么,有什么作用

WAAP全站防护是基于风险管理和WAAP理念打造的安全方案&#xff0c;以“体系化主动安全” 取代安全产品的简单叠加&#xff0c;为各类Web、API业务等防御来自网络层和应用层的攻击&#xff0c;帮助企业全面提升Web安全水位和安全运营效率。 主要的特性在于&#xff1a; 1.全周…

C语言例:设 int a=11; 则表达式 a+=a-=a*a 的值

注&#xff1a;软件为VC6.0 代码如下&#xff1a; #include<stdio.h> int main(void) {int a11, b;b (aa-a*a); //a*a121 -->a-121结果为a-110 -->a-110结果为a-220printf("表达式aa-a*a 的值为&#xff1a; %d\n",b);return 0; } //优先级&#x…

ADO .Net操作SQL Server数据库

//ADO.NET是.NET Framework提供的数据访问服务的类库&#xff0c;应用程序可以使用ADO.NET连接到这些数据源&#xff0c;并检索、处理和更新数据 //常用的数据源包括四种&#xff1a;&#xff08;1&#xff09;Microsoft SQL Server数据源&#xff1a;使用System.Data.SqlClien…

DC-1靶机渗透测试

DC-1靶机渗透测试 一、信息搜集1、嗅探寻找存活主机2、查找开放端口3、查找敏感目录 二、漏洞利用1、web访问2、寻找Drupal 的config文件3、寻找网站登录密码4、寻找靶机的用户名和密码5、远程登录6、提权 一、信息搜集 1、嗅探寻找存活主机 命令&#xff1a;arp-scan -l 找到…

基于单片机的智能小车泊车系统设计

摘 要:随着信息技术的进步,汽车逐渐朝着安全、智能方向发展,智能泊车系统的出现不仅能帮助人们更加快速、安全地完成泊车操作,而且适用于狭小空间的泊车操作,降低驾驶员泊车负担,减轻泊车交通事故发生率。文章基于单片机设计自动泊车系统,以单片机为核心来实现信息收集及…

【Numpy】练习题100道(51-75题)

&#x1f33b;个人主页&#xff1a;相洋同学 &#x1f947;学习在于行动、总结和坚持&#xff0c;共勉&#xff01; #学习笔记# Git-hub链接 目录 1.题目列表 2.题解 1.题目列表 51. 创建一个表示位置&#xff08;x,y&#xff09;和颜色&#xff08;r,g,b&#xff09;的结…

C#控制台贪吃蛇

Console.Write("");// 第一次生成食物位置 // 随机生成一个食物的位置 // 食物生成完成后判断食物生成的位置与现在的蛇的身体或者障碍物有冲突 // 食物的位置与蛇的身体或者障碍物冲突了&#xff0c;那么一直重新生成食物&#xff0c;直到生成不冲突…

19双体系Java学习之数组的Arrays类

数组的Arrays类 ★小贴士 sort方法对数组进行排序&#xff0c;方法调用完成后&#xff0c;数组按升序排列。 binarySearch方法对数组进行二分查找&#xff0c;如果能找到需要查找的元素则返回该元素的下标&#xff0c;否则返回一个负数&#xff0c;详见binarySearch的范例代码。…

如何将Excel两列数据转换为统计图、曲线图、折线图?如何自定义某一列作为Excel的统计图横纵坐标?

这样&#xff0c;横坐标就更换为指定选中的数据了 我们还可以修改统计图的样式 也可以修改统计图的类型

代码随想录算法训练营第41天 | 01背包问题(二维+一维) ,416. 分割等和子集

动态规划章节理论基础&#xff1a; https://programmercarl.com/%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92%E7%90%86%E8%AE%BA%E5%9F%BA%E7%A1%80.html 01背包理论基础 链接&#xff1a;https://programmercarl.com/%E8%83%8C%E5%8C%85%E7%90%86%E8%AE%BA%E5%9F%BA%E7%A1%8001%…

redis学习-List类型相关命令以及特殊情况分析

目录 1. lpush key value1 value2 ... 2. lrange key start end 3. lpop key num 4. rpush key value1 value2 ... 5. rpop key num 6. lindex key index 7. llen key 8. lrem key num value 9. rpoplpush key1 key2 10. lset key index value 11. linsert key before/after…

Python基础算法解析:支持向量机(SVM)

支持向量机&#xff08;Support Vector Machine&#xff0c;SVM&#xff09;是一种用于分类和回归分析的机器学习算法&#xff0c;它通过在特征空间中找到一个最优的超平面来进行分类。本文将详细介绍支持向量机的原理、实现步骤以及如何使用Python进行编程实践。 什么是支持向…

栈与队列|150.逆波兰表达式求值

力扣题目链接 class Solution { public:int evalRPN(vector<string>& tokens) {// 力扣修改了后台测试数据&#xff0c;需要用longlongstack<long long> st; for (int i 0; i < tokens.size(); i) {if (tokens[i] "" || tokens[i] "-&qu…

南卡罗来纳州历史和文化经济地理和自然政治和社会教育1. 加州大学公布2024年秋季入学新生和转学申请数据2. 2024考研国家线公布路德会信徒核心信仰礼拜和

目录 南卡罗来纳州 历史和文化 经济 地理和自然 政治和社会 教育 1. 加州大学公布2024年秋季入学新生和转学申请数据 2. 2024考研国家线公布 路德会信徒 核心信仰 礼拜和实践 分布 社会和文化影响 约翰塞巴斯蒂安巴赫 生平简介 音乐风格和作品 遗产和影响 …

【Spring 篇】SpringMVC拦截器:给你的应用增添色彩

嗨&#xff0c;亲爱的小伙伴们&#xff01;欢迎来到这段关于SpringMVC拦截器的奇妙之旅。今天我们要一探究竟&#xff0c;深入挖掘拦截器的神秘面纱&#xff0c;看看它是如何在你的应用中悄然发挥作用的。别怕&#xff0c;我会用最通俗易懂的语言&#xff0c;一步一步带你走进这…

银行合规线上知识竞赛活动方案

合规知识大闯关 作为全国竞赛氛围预热项目&#xff0c;组织市县中心、代理网点人员参与合规知识大闯关答题。 1.建立线上答题平台&#xff0c;参与人通过手机、电脑等方式&#xff0c;填写个人基本信息登录。 2.答题平台在题库中随机抽取试题。 3.参与人在出现第一次答错后&…

spring boot nacos注册微服务示例demo_亲测成功

spring boot nacos注册微服务示例demo_亲测成功 先安装好Nacos Nacos安装使用 创建Maven项目 结构如图 例如项目名为: test-demo 下面有个子模块: test-demo-data-process 父模块pom.xml <?xml version"1.0" encoding"UTF-8"?> <project …