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

1 前言 

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

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

import openai
import os

from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv()) # read local .env file

openai.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 foam

COUNTRY 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 a
 mid-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-110

Product 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>
'''

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

代码随想录阅读笔记-哈希表【三数之和】

题目 给你一个包含 n 个整数的数组 nums&#xff0c;判断 nums 中是否存在三个元素 a&#xff0c;b&#xff0c;c &#xff0c;使得 a b c 0 &#xff1f;请你找出所有满足条件且不重复的三元组。 注意&#xff1a; 答案中不可以包含重复的三元组。 示例&#xff1a; 给定数…

Python之Web开发中级教程----搭建虚拟环境

Python之Web开发中级教程----搭建Web框架二 搭建虚拟环境 虚拟环境的作用 虚拟环境可以搭建独立的python运行环境, 使得单个项目的运行环境与其它项目互不影响. 搭建虚拟环境 &#xff08;1&#xff09;安装 sudo pip install virtualenv sudo pip install virtualenvwra…

一起学数据分析_2

写在前面&#xff1a;代码运行环境为jupyter&#xff0c;如果结果显示不出来的地方就加一个print()函数。 一、数据基本处理 缺失值处理&#xff1a; import numpy as np import pandas as pd#加载数据train.csv df pd.read_csv(train_chinese.csv) df.head()# 查看数据基本…

Vue3-响应式基础:单文件和组合式文件

单文件&#xff1a;html <!DOCTYPE html> <html> <head><title>响应式基础</title> </head> <body><div id"app" ><!-- dynamic parameter:同样在指令参数上也可以使用一个 JavaScript 表达式&#xff0c;需要包…

简易版 RPC 框架实现 1.0 -http实现

RPC 是“远程过程调用&#xff08;Remote Procedure Call&#xff09;”的缩写形式&#xff0c;比较通俗的解释是&#xff1a;像本地方法调用一样调用远程的服务。虽然 RPC 的定义非常简单&#xff0c;但是相对完整的、通用的 RPC 框架涉及很多方面的内容&#xff0c;例如注册发…

离散时间傅里叶变换和离散傅里叶变换

离散时间傅里叶变换和离散傅里叶变换 { X ( k ) DFT [ x ( n ) ] ∑ n 0 N − 1 x ( n ) W N n k k 0 , 1 , . . . , N − 1 x ( n ) IDFT [ X ( k ) ] 1 N ∑ n 0 N − 1 x ( n ) W N − n k n 0 , 1 , . . . , N − 1 \begin{cases} X(k)\textbf{DFT}[x(n)]\sum\limi…

解决:IDEA编译Java程序时报编译失败

1、问题展示&#xff1a; 2、解决方法&#xff1a;

Magical Combat VFX

这个包包含30个可供游戏使用的VFX,有各种口味,为您的游戏增添趣味! 所有VFX都经过了很好的优化,可以在所有平台上使用。 这个包特别有一堆闪电魔法,有两种主要的变体,一种是深色的,另一种是浅色的。但它也提供了一系列其他视觉效果,如神圣咒语、音乐主题等等! 我们提供…

【CSP】2021-09-2 非零段划分 索引+递推/差分+前缀和

2021-09-2 非零段划分 索引递推/差分前缀和 2021-09-2 非零段划分 索引递推/差分前缀和索引递推思路差分前缀和思路遇到的问题索引递推完整代码差分前缀和完整代码 2021-09-2 非零段划分 索引递推/差分前缀和 一开始写的时候没有发现直接从a数组求q的规律&#xff0c;怎么也想…

NCV8705MTADJTCG稳压器芯片中文资料规格书PDF数据手册引脚图图片价格功能

产品概述&#xff1a; NCV8705 是一款低噪音、低功耗和低泄漏线性电压稳压器。该器件具有卓越的噪音和 PSRR 规格&#xff0c;适用于使用视频接收器、成像传感器、音频处理器或需要外部洁净电源的任何部件的产品。NCV8705 使用创新的自适应接地电流电路 可确保轻负载调节下的超…

基于DFA敏感词查询的算法简析

基于DFA敏感词查询的算法简析 1.背景 项目中需要对敏感词做一个过滤&#xff0c;首先有几个方案可以选择&#xff1a; a.直接将敏感词组织成String后&#xff0c;利用indexOf方法来查询。 b.传统的敏感词入库后SQL查询。 c.利用Lucene建立分词索引来查询。 d.利用DFA算法…

3.python安装Selenium框架

1. 命令安装 pip install selenium下载慢,可以换源: pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/查看是否换源成功 pip config get global.index-url安装好后,查看版本信息: pip show selenium2.下载对应的浏览器驱动 https://registry.npmm…

【Elasticsearch】windows安装elasticsearch教程及遇到的坑

一、安装参考 1、安装参考&#xff1a;ES的安装使用(windows版) elasticsearch的下载地址&#xff1a;https://www.elastic.co/cn/downloads/elasticsearch ik分词器的下载地址&#xff1a;https://github.com/medcl/elasticsearch-analysis-ik/releases kibana可视化工具下载…

Vue2 引入使用ElementUI详解

目录 1 安装2 引入2.1 全局引入2.1.1 引入2.1.2 使用 2.2 按需引入2.2.1 引入2.2.2 使用 3 总结 1 安装 推荐使用 npm 的方式安装&#xff0c;它能更好地和 webpack打包工具配合使用。&#xff08;本项目使用安装方式&#xff09; npm i element-ui -S也可以使用其他的包管理…

Notepad++从文件夹查找文本内容

目录 一、背景二、Notepad搜索2.1 测试用例2.2 操作说明 一、背景 在日常的办公、学习或编程中&#xff0c;我们时长会遇到需要在大量文件中搜索特定文本内容的情况&#xff1a; 无论是快速定位某个项目中的代码片段&#xff1b;还是检索文档资料库中的相关信息等。 掌握如何…

蓝桥杯:模拟、枚举

目录 引言一、修剪灌木二、特殊年份三、刷题统计 引言 本篇文章主要介绍蓝桥杯的模拟和枚举的题目&#xff0c;这种题在 B B B 组还是比较简单的&#xff0c;后续也会一直往里加新的真题&#xff0c;加油&#xff01; 一、修剪灌木 标签&#xff1a;第十三届蓝桥杯省赛C B组…

音乐创作利器FL Studio21水果软件助你轻松实现音乐创意

音乐创作利器——FL Studio21水果软件&#xff0c;让你的音乐梦想起航&#xff01; 副标题&#xff1a;一款强大的电脑数码编曲软件&#xff0c;助你轻松实现音乐创意&#xff01; 一、FL Studio21水果软件——音乐制作的得力助手** 在音乐创作的道路上&#xff0c;有一款得心…

uniapp样式穿透修改uview的按钮button图标

需求&#xff1a; 想给按钮icon和text改字体颜色&#xff0c;结果发现图标颜色并没有改变 .u-button{width: 300rpx;background-color: aliceblue;color: #aaaa7f;margin-top: 20rpx; }接下来用样式穿透解决 1、首先&#xff0c;给UI组件包裹一层view <view class"t…

Javaweb学习记录(一)Maven

Maven是一款Java项目管理工具&#xff0c;下面将介绍Maven的实际作用和相关的操作 Maven项目依赖的添加 在Maven项目中添加依赖&#xff0c;通过dependencies标签添加所有依赖&#xff0c;所有依赖都添加在里面&#xff0c;而单个依赖就使用dependency标签添加进项目&#xf…

文章解读与仿真程序复现思路——电网技术EI\CSCD\北大核心《考虑抽水蓄能电站参与容量交易辅助服务的双层优化策略》

本专栏栏目提供文章与程序复现思路&#xff0c;具体已有的论文与论文源程序可翻阅本博主免费的专栏栏目《论文与完整程序》 论文与完整源程序_电网论文源程序的博客-CSDN博客https://blog.csdn.net/liang674027206/category_12531414.html 电网论文源程序-CSDN博客电网论文源…