吴恩达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.hqwc.cn/news/539425.html

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

相关文章

PHP中的反序列化漏洞

PHP中的反序列化漏洞 目录 PHP 中的序列化与反序列化 概述 序列化 基本类型的序列化 对象的序列化 反序列化 示例序列化与反序列化 反序列化漏洞 - PHP 中的魔术方法 - Typecho_v1.0 中的反序列化漏洞 POP链的构造思路 pop链案例 反序列化逃逸 字符串逃逸&#xff…

发布组件到npm

1.环境准备&#xff0c;需要装好node&#xff0c;注册号npm账号,这里不做详解 2.创建编写组件和方法的文件夹package 3.在文件夹中创建需要定义的组件&#xff0c;并且加上name属性 //组件 <template><div><button>按钮组件</button></div> &…

微服务分布式springcloud的体育场地预约系统演kdm1z

体育场馆设施预约系统是在实际应用和软件工程的开发原理之上&#xff0c;运用java语言以及Springcloud框架进行开发。首先要进行需求分析&#xff0c;分析出体育场馆设施预约系统的主要功能&#xff0c;然后设计了系统结构。整体设计包括系统的功能、系统总体结构、系统数据结构…

MySQL order by 语句执行流程

全字段排序 假设这个表的部分定义是这样的&#xff1a; CREATE TABLE t (id int(11) NOT NULL,city varchar(16) NOT NULL,name varchar(16) NOT NULL,age int(11) NOT NULL,addr varchar(128) DEFAULT NULL,PRIMARY KEY (id),KEY city (city) ) ENGINEInnoDB; 有如下 SQL 语…

【深度学习笔记】9_8 区域卷积神经网络(R-CNN)系列

注&#xff1a;本文为《动手学深度学习》开源内容&#xff0c;部分标注了个人理解&#xff0c;仅为个人学习记录&#xff0c;无抄袭搬运意图 9.8 区域卷积神经网络&#xff08;R-CNN&#xff09;系列 区域卷积神经网络&#xff08;region-based CNN或regions with CNN feature…

基于物联网的智能家居监测与控制系统(全套资料)

项目源码资料下载地址&#xff1a; http://comingit.cn/?id29 易学蔚来全套毕设演示&#xff08;看上哪个选那个&#xff09;&#xff1a; https://www.yuque.com/javagongchengshi/ccadbu/nh92kcpyqodhf07l 毕设服务真实反馈&#xff0c;在线观看&#xff1a; https://www.yu…

Java基于微信小程序的校园订餐小程序的研究与实现,附源码

博主介绍&#xff1a;✌程序员徐师兄、7年大厂程序员经历。全网粉丝12w、csdn博客专家、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌ &#x1f345;文末获取源码联系&#x1f345; &#x1f447;&#x1f3fb; 精彩专栏推荐订阅&#x1f447;…

Tomcat下载安装及纯手动发布一个应用

文章目录 javaWeb介绍一. 下载tomcat二、部署Web项目准备三. 验证tomcat配置是否成功四、安装包中各个文件的解释与用途五、纯手动部署web项目 javaWeb介绍 1、什么是JavaWeb&#xff1f; JavaWeb是一种使用Java语言编写的基于Web的应用程序开发技术。它是通过Java的Web开发框…

一键切割,激发无限创意:体验全新图片批量编辑器

在数字创意的时代&#xff0c;图片编辑成为了表达个性和创造力的关键。然而&#xff0c;传统的图片编辑工具常常让人望而生畏&#xff0c;复杂的操作和高门槛的技术要求使得许多人望而却步。现在&#xff0c;我们为您带来一款全新的图片批量编辑器&#xff0c;只需一键切割&…

sql注入重学

sql基本操作 基本查询语句 union (必须得是前面的列与后面的列相同才可以查询&#xff09; 看第二局uses表中的列有3列&#xff0c;而emails中的列只有两列&#xff0c;所有无法成功查询 这就相当于我们再加了一列 group by &#xff08;分组&#xff09; 相当于将其分为10列…

20232831 2023-2024-2 《网络攻防实践》第2次作业

目录 20232831 2023-2024-2 《网络攻防实践》第2次作业1.实验内容2.实验过程3.学习中遇到的问题及解决4.学习感悟、思考等参考资料 20232831 2023-2024-2 《网络攻防实践》第2次作业 1.实验内容 &#xff08;1&#xff09;从www.csdn.net、www.163.com等中选择一个DNS域名进行…

服务器Debian 12.x中安装Jupyer并配置远程访问

服务器系统&#xff1a;Debian 12.x&#xff1b;IP地址&#xff1a;10.100.2.138 客户端&#xff1a;Windows 10;IP地址&#xff1a;10.100.2.38 利用ssh登录服务器&#xff1a; 1.安装python3 #apt install python3 2.安装pip #apt install python3-pip … 3.安装virtualen…