吴恩达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,一经查实,立即删除!

相关文章

【Docker】Kong 容器化部署及配置参数说明

Kong标准软件基于Bitnami apache 构建。当前版本为2.4.58 你可以通过轻云UC部署工具直接安装部署&#xff0c;也可以手动按如下文档操作&#xff0c;该项目已经全面开源&#xff0c;可以从如下环境获取 配置文件地址: https://gitee.com/qingplus/qingcloud-platform qinghub…

elasticsearch常见问题:xpack.security.transport.ssl、unknown setting [node.master]

文章目录 引言I 安装elasticsearch1.1 安装Master Node1.2 安装Slave nodeII elasticsearch常见问题2.1 invalid configuration for xpack.security.transport.ssl2.2 server ssl configuration requires a key and certificate2.3 unknown setting [node.master]III Kibana启动…

两台 CentOS 之间传数据:SCP 方式

两台 CentOS 之间传数据&#xff1a;SCP 方式 文章目录 两台 CentOS 之间传数据&#xff1a;SCP 方式一、CentOS 安装 SSH 服务0、注意1、更新系统2、安装 OpenSSH 服务器3、启动 SSH 服务4、检查SSH服务状态5、配置防火墙6、测试 SSH 连接7、更改SSH默认端口(可选) 二、文件传…

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; 现场总线…

【好玩的经典游戏】Docker环境下部署经典贪吃蛇小游戏

【好玩的经典游戏】Docker环境下部署经典贪吃蛇小游戏 前言一、相关介绍1.1 httpd介绍1.2 贪吃蛇小游戏介绍二、本地环境介绍2.1 本地环境规划2.2 本次实践介绍三、检查本地环境3.1 检查系统版本3.2 检查Docker服务状态四、下载httpd镜像五、创建httpd容器5.1 新建目录5.2 创建…

开源项目_搭建对象存储服务MinIO

1 简介 MinIO 是一个开源的对象存储服务器&#xff0c;与 Amazon S3 兼容。它的设计目标是为大规模数据工作负载提供简单、安全和高性能的存储。 以下是 MinIO 的一些主要特性&#xff1a;高性能&#xff0c;S3 兼容&#xff0c;安全性&#xff0c;可扩展性&#xff0c;开源&…

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

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

学习Java十一天总结

目录 一、走进Java编程世界 二、变量、常量和运算符 三、if选择结构 四、switch选择结构 五、while循环结构 六、for循环结构 七、数组 八、深度循环结构 九、类和对象 十、类的无参方法 十一、类的带参方法 十二、字符串 一、走进Java编程世界 程序是为了让计算机…

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…

常用pip命令

pip是一个现代的&#xff0c;通用的Python包管理工具。它提供了对Python包的查找、下载、安装、卸载的功能。 安装库 pip install package_name如果你想从特定的源安装&#xff0c;可以使用-i或--index-url选项&#xff1a; pip install package_name -i https://pypi.examp…

mac安装rust环境

mac安装rust环境 老规矩官方文档 1. mac官网使用的是脚本安装, 至于为啥没使用brew也没推荐俺也不太清楚 curl --proto https --tlsv1.2 -sSf https://sh.rustup.rs | sh2. 一般来说中途会遇见有一个选择我这里选择直接回车默认安装(如果以后我研究明白的话会进行更新, 现在是…

Java-Thread 几种创建方式

Thread 创建线程的四种方法&#xff1a; 继承Thread类创建线程类&#xff0c;然后创建线程实例。实现Runnable借口创建线程目标类&#xff0c;然后创建线程实例。使用Callable和FutureTask创建异步任务&#xff0c;然后创建线程实例。通过线程池创建线程 Runnable异步任务的…

ADO .Net操作SQL Server数据库

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

Python3 字符编解码

Python3 字符编解码 什么是字符编解码 编码&#xff1a;根据编码格式将人类认识的字符转为字节流。解码&#xff1a;根据编码格式将字节流转为人类认识的字符。 Python3 中的字符编码 utf-8为Python3的默认编码格式&#xff0c;可通过以下语句查看&#xff1a; import sys p…

MongoDB聚合运算符:$floor

文章目录 语法使用举例 $floor聚合运算符返回小于等于指定数值的最大整数&#xff0c;相当于取整函数。 语法 { $floor: <number> }<number>表达式为数值表达式。 使用 如果参数<number>的值为null或引用的字段不存在&#xff0c;$floor返回null&#xf…

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;的结…