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

news/2024/7/5 3:54:35

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


http://lihuaxi.xjx100.cn/news/2100985.html

相关文章

数据库表结构导出工具【人生的第一个开源工具】

数据库表结构导出工具 如今我努力奔跑&#xff0c;不过是为了追上那个曾经被寄予厚望的自己 —— 约翰。利文斯顿 本工具是一个用于将数据库表结构导出到 Word 文档的实用工具。它能够连接到指定的数据库&#xff0c;提取数据库中所有表的结构信息&#xff0c;并将这些信息以专…

Linux之shell文本搜索工具grep

华子目录 文本搜索工具grep作用格式参数注意示例 正则表达式概念基本正则表达式常见元字符posix字符类示例 扩展正则表达式概念元字符示例三种支持扩展正则的方法 文本搜索工具grep 作用 grep是linux中一种强大的文件搜索过滤工具&#xff0c;可以按照正则表达式检索文件内容…

UG NX二次开发(C++)-CAM-获取加工操作的四种方法

文章目录 1、前言2、采用选中工序导航器获取操作的Tag_t3、采用遍历对象的方法获取操作的Tag_t4、采用Collection遍历获取操作对象NXOpen::CAM::Operation5、采用FindObject获取操作对象NXOpen::CAM::Operation6、以上4种方法封装成类 Class CAMOperation6.1 CAMOperation.h文件…

用pako.js压缩字符串,如何在后端用java解开?

背景&#xff1a;项目链路为腾讯clb->Ingress(nginx)->项目服务,腾讯的Ingress对header请求头最大值为256K&#xff0c;无法加大&#xff0c;由于业务配置数据增加&#xff0c;此问题诟病已久&#xff0c;于是想着压缩打请求头数据后再请求&#xff0c;从而解决请求头大的…

一套为中小电商企业构建的、开源的、简单实用的ERP系统需要接入的电商API接口以及实现的功能模块分析

一、项目简介 电商ERP系统为中小电商企业构建的一套简单实用的电商系统&#xff0c;本项目采用Java SpringBootVue2前后端分离开发。 支持供应商一件代发和仓库发货两种发货方式&#xff0c;主体流程覆盖采购、网店订单处理、供应商一件代发、仓库发货、网店售后、仓库出入库、…

[C++] 实现Union

前几天学了replacement new写的小玩意 #include <iostream> #include <functional> #include <string>// 可能因为const char*类型的缘故 // 用const ArgsT&&...会报错// 测试用类 struct Test {Test(){std::cout << "constructed"…

Unity2019.2.x 导出apk 安装到安卓Android12+及以上的系统版本 安装出现-108 安装包似乎无效的解决办法

Unity2019.2.x 导出apk 安装到安卓Android12及以上的系统版本 安装出现-108 安装包似乎无效的解决办法 导出AndroidStudio工程后 需要设置 build.gradle文件 // GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAINbuildscript {repositor…

【洛谷 P8602】[蓝桥杯 2013 省 A] 大臣的旅费 题解(图论+深度优先搜索+树的直径+链式前向星)

[蓝桥杯 2013 省 A] 大臣的旅费 题目描述 很久以前&#xff0c;T 王国空前繁荣。为了更好地管理国家&#xff0c;王国修建了大量的快速路&#xff0c;用于连接首都和王国内的各大城市。 为节省经费&#xff0c;T 国的大臣们经过思考&#xff0c;制定了一套优秀的修建方案&am…