OpenAI官方吴达恩《ChatGPT Prompt Engineering 提示词工程师》(2)如何迭代开发提示词

news2024/10/6 4:09:14

迭代/Iterative


在机器学习中,您经常有一个想法,然后实现它。编写代码,获取数据,训练模型,这就给您一个实验结果。然后您可以查看该输出,进行错误分析,找出哪些地方工作或不工作,然后甚至可以改变您要解决的问题或如何处理它的确切想法,并更改实现并运行另一个实验等,一遍又一遍地迭代,以获得有效的机器学习模型。
在写prompt提示词的时候,该过程可能非常相似,您可以有一个关于您想要完成的任务的想法,然后尝试编写第一个提示,希望它清晰具体,并可能在适当的情况下给系统一些时间来思考,然后运行它并查看结果。

  • Be clear and specific
  • Analyze why result does not give desired output.
  • Refine the idea and the prompt
  • Repeat

Iterative Process

  • Try something
  • Analyze where the result does not give what you want
  • Clarify instructions, give more time to think 澄清您的指令,或者在某些情况下,考虑给它更多的思考空间,以使其更接近于产生您想要的结果。
  • Refine prompts with a batch of examples对多个示例进行提示评估可能是有用的,以查看平均或最差情况的性能如何

环境准备

和上文内容(①指南)一样进行环境的准备,获取openAI秘钥。

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

案例:生成产品描述

这是一个椅子的事实表,其中描述了它是一个美丽的中世纪灵感家族的一部分,讲述了构造,尺寸,椅子选项,材料等。它来自意大利。所以,假设您想要将这个事实表提供给营销团队,以帮助他们为在线零售网站撰写描述。

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

我的提示是:您的任务是帮助营销团队基于技术事实表为零售网站或产品创建描述,编写产品描述等。


Python
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 our stunning mid-century inspired office chair, the perfect addition to any home or business setting. Part of a beautiful family of office furniture, including filing cabinets, desks, bookcases, meeting tables, and more, this chair is available in several options of shell color and base finishes to suit your style. Choose from plastic back and front upholstery (SWC-100) or full upholstery (SWC-110) in 10 fabric and 6 leather options.

The chair is constructed with a 5-wheel plastic coated aluminum base and features a pneumatic chair adjust for easy raise/lower action. It is available with or without armrests and is qualified for contract use. The base finish options are stainless steel, matte black, gloss white, or chrome.

Measuring at a width of 53 cm, depth of 51 cm, and height of 80 cm, with a seat height of 44 cm and seat depth of 41 cm, this chair is designed for ultimate comfort. You can also choose between soft or hard-floor caster options and two choices of seat foam densities: medium (1.8 lb/ft3) or high (2.8 lb/ft3). The armrests are available in either an armless or 8 position PU option.

The materials used in the construction of this chair are of the highest quality. The shell base glider is made of cast aluminum with modified nylon PA6/PA66 coating and has a shell thickness of 10 mm. The seat is made of HD36 foam, ensuring maximum comfort and durability.

This chair is made in Italy and is the perfect combination of style and functionality. Upgrade your workspace with our mid-century inspired office chair today!
"""

1、修改输出字数

修改提示:使用最多50个单词来更好地指导所需长度

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. #修改提示
#Use at most 280 charact 
#Use at most 3 sentences.

Technical specifications: ``{fact_sheet_chair}``
"""
response = get_completion(prompt)
print(response)
...
Introducing our mid-century inspired office chair, part of a beautiful furniture family. Available in various shell colors and base finishes, with plastic or full upholstery options in fabric or leather. Suitable for home or business use, with a 5-wheel base and pneumatic chair adjust. Made in Italy.
...

2、修改面向用户

这个描述不是直接销售给消费者,而是旨在向家具零售商销售家具,因此应该是技术性的,重点放在材料、产品和构造方面。

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.

Use at most 50 words.

Technical specifications: ``{fact_sheet_chair}``
"""
response = get_completion(prompt)
print(response)
"""
Introducing our mid-century inspired office chair, perfect for both home and business settings. With a range of shell colors and base finishes, including stainless steel and matte black, this chair is available with or without armrests. The 5-wheel plastic coated aluminum base and pneumatic chair adjust make it easy to move and adjust to your desired height. Made with high-quality materials, including a cast aluminum shell and HD36 foam seat, this chair is built to last.
"""

在描述的结尾处,我还想包括产品ID。包括每个7个字符的产品ID。

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)
"""
chair, perfect for home or business settings. With a range of shell colors and base finishes, and the option of plastic or full upholstery, this chair is both stylish and comfortable. Constructed with a 5-wheel plastic coated aluminum base and pneumatic chair adjust, it's also practical. Available with or without armrests and suitable for contract use. Product ID: SWC-100, SWC-110.
"""

3、表格输出

给出产品尺寸的表格,然后将所有内容格式化为HTML

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)
"""
<div>
<h2>Mid-Century Inspired Office Chair</h2>
<p>Introducing our mid-century inspired office chair, part of a beautiful family of office furniture that includes filing cabinets, desks, bookcases, meeting tables, and more. This chair is available in several options of shell color and base finishes, allowing you to customize it to your liking. You can choose between plastic back and front upholstery or full upholstery in 10 fabric and 6 leather options. The base finish options are stainless steel, matte black, gloss white, or chrome. The chair is also available with or without armrests, making it suitable for both home and business settings. Plus, it's qualified for contract use, ensuring its durability and longevity.</p>
<p>The chair's construction features a 5-wheel plastic coated aluminum base and a pneumatic chair adjust for easy raise/lower action. You can also choose between soft or hard-floor caster options and two choices of seat foam densities: medium (1.8 lb/ft3) or high (2.8 lb/ft3). The armrests are also customizable, with the option of armless or 8 position PU armrests.</p>
<p>The materials used in the chair's construction are of the highest quality. The shell base glider is made of cast aluminum with modified nylon PA6/PA66 coating, with a shell thickness of 10 mm. The seat is made of HD36 foam, ensuring maximum comfort and support.</p>
<p>Made in Italy, this mid-century inspired office chair is the perfect addition to any office space. Order yours today!</p>
<h3>Product IDs:</h3>
<ul>
<li>SWC-100</li>
<li>SWC-110</li>
</ul>
</div>

<table>
  <caption>Product Dimensions</caption>
  <tr>
    <th>Dimension</th>
    <th>Measurement (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>
"""

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

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

相关文章

瞬态执行攻击与防御的评估

作者&#xff1a;Claudio Canella, Jo Van Bulck, Michael Schwarz, Moritz Lipp, Benjamin von Berg, Philipp Ortner, Frank Piessens, Dmitry Evtyushkin, Daniel Gruss: 标题&#xff1a;A Systematic Evaluation of Transient Execution Attacks and Defenses. 发布&#…

写代码生成流程图

我们在写文档&#xff0c;博客的时候&#xff0c;一般都会使用markdown语法&#xff0c;最常见的就是一些github开源项目的README。有时候会去画一些流程图&#xff0c;例如使用process.on或者xmind等第三方网站&#xff0c;然后截图插入到文档中。 今天我们介绍一种使用代码直…

如何用手机给自己拍摄的视频静音?

我们在分享视频的时候常常会遇到这种情况&#xff0c;视频有杂音或音乐声太大&#xff0c;这个时候就需要用到视频静音这个功能了&#xff0c;将视频静音后&#xff0c;可以根据自己的需求重新配乐或配音&#xff0c;下面附上详细操作步骤&#xff0c;大家看好学好&#xff01;…

nginx配置密码访问

安装htpasswd 因为需要使用到htpasswd&#xff0c;htpasswd是Apache服务器中生成用户认证的一个工具&#xff0c;如果未安装&#xff0c;则使用如下命令安装htpasswd。 yum install -y httpd-tools设置用户名和密码 htpasswd 安装成功后&#xff0c;就可以设置用户名和密码&am…

搭建智能桥梁,Amazon CodeWhisperer助您轻松编程

零&#xff1a;前言 随着时间的推移&#xff0c;人工智能技术以惊人的速度向前发展&#xff0c;正掀起着全新的编程范式革命。不仅仅局限于代码生成&#xff0c;智能编程助手等创新应用也进一步提升了开发效率和代码质量&#xff0c;极大地推动着软件开发领域的快速繁荣。 当前…

火车头采集器python CHATGPT/AI改写插件使用教程!

大家好我是淘小白&#xff0c;关于火车头的AI改写插件的环境配置和使用教程&#xff0c;今天来给大家整理一下&#xff0c;请购买过的朋友&#xff0c;按照这个教程自行操作~ 1、规则&插件 这是我们拿到的演示规则和插件 2、配置环境 首先&#xff0c;要先安装Python&…

如何通过bat批处理实现快速生成文件目录,一键生成文件名和文件夹名目录

碰对了情人&#xff0c;相思一辈子。 具体方法步骤&#xff1a; 一、创建一个执行bat文件&#xff08;使用记事本即可&#xff09;&#xff1b; 1、新建一个txt文本空白记事本文件 2、复制以下内容进记事本内 dir/a/s/b>LIST.TXT &#xff08;其中LIST.TXT文件名是提取后将…

“益路同行”专访第0002期—张掖市汇仁爱心公益协会创始人谢建英

中国善网在本届&#xff08;第十届&#xff09;慈展会上特别推出了《益路同行》采访栏目&#xff0c;《益路同行》栏目旨在寻觅公益之路上同行者的故事&#xff0c;挖掘公益更深层次的内涵&#xff0c;探索新时代公益发展道路。希望公益企业、人物、故事被更多人看到&#xff0…

RFID服装工位管理提高生产管理效率

RFID服装工位管理是一种通过使用RFID电子标签来提高制造企业生产管理效率的方法&#xff0c;在传统的制造企业中&#xff0c;生产流程通常以单件为主&#xff0c;当生产环节繁复且工序众多时&#xff0c;容易出现各种问题。特别是在劳动密集型行业&#xff0c;如服装制造业&…

Mini Linux嵌入式设备服务器

Digi International推出了具有Digi Embedded Linux的Digi Connect ME 9210。Digi Embedded Linux是为在Digi嵌入式模块和微控制器上开发而优化的最新版本。高性能嵌入式开发服务器大约只有一对骰子大小&#xff0c;是嵌入式Linux上最小的。这使OEM可以在空间受限的设备中使用Li…

StarRocks数据导入

1、相关环境 Flink作为当前流行的流式计算框架&#xff0c;在对接StarRocks时&#xff0c;若直接使用JDBC的方式"流式"写入数据&#xff0c;对StarRocks是不友好的&#xff0c;StarRocks作为一款MVCC的数据库&#xff0c;其导入的核心思想还是"攒微批降频率&qu…

Unity把UGUI再World模式下显示到相机最前方

Unity把UGUI再World模式下显示到相机最前方 通过脚本修改Shader 再VR里有时候要把3D的UI显示到相机最前方&#xff0c;加个UI相机会坏事&#xff0c;可以通过修改unity_GUIZTestMode来解决。 测试用例 测试用例如下&#xff1a; 场景包含一个红色的盒子&#xff0c;一个UI…

十,从摄像机打印立方体的一个外表面

从摄像机是与主摄像机保持同样的投影矩阵&#xff0c;所以&#xff0c;不用单独设置。如果把漫游器还是在&#xff08;1&#xff0c;0,0)这个位置&#xff0c;各个从摄像机看向上下左右前后六个面&#xff0c;那么会出现什么现象呢&#xff1f;应该是x正轴打印出来&#xff0c;…

DataOps课程:DataOps实施,花更少的时间发现和纠正错误 | 内附视频

《DataOps实施》课程内容包括《数据之旅第一数据运营》《精益数据运营的四个阶段》《DataOps的流程及结论》。本文汲取课程精华要点&#xff0c;如需完整版可观看视频讲解&#xff0c;关注公众号回复关键字【第五课】&#xff0c;获取课程完整版文字内容。 课程完整版&#xff…

IT项目管理十大模版(三)

一、项目组成员表 要把项目组成员的名单都罗列出来&#xff0c;形成一个有效的团队&#xff1b;成员角色和职责要写清楚&#xff0c;职责分明、各司其职&#xff1b;领导审核并签字确认。 二、项目范围说明书 此表&#xff0c;包含了6个部分&#xff0c;基本情况、项目描述…

训练聊天机器人,改善客户体验

谈及对待客户&#xff0c;最重要的一点便是尊重他们&#xff0c;并尊重他们的时间。这意味着在与客户互动过程中&#xff0c;回应需及时有用&#xff0c;而且要赢得回头客尤是如此。社会约定俗成的期望是&#xff1a;客户能够全天候随时提出问题&#xff0c;并获得近乎即时的回…

终于有人能说清火爆全网的AIGC了 | 附赠试用

AIGC全称为AI Generated Content&#xff0c;直译为人工智能生产的内容&#xff0c;认为是继PGC、UGC之后的新型内容创作方式。也是现在市场最火的”AI“概念的延伸应用。 AIGC之以这么热门&#xff0c;主要因为其上手非常简单大大降低了创作门槛&#xff0c;只需用文字描述您想…

FPGA行业应用一:LED控制器

什么是LED控制器 LED控制器已经有很多年头了&#xff0c;应该是上世纪90年代就开始有了。它的主要构成是&#xff1a; 1&#xff1a;视频信号源——如 电脑&#xff0c;机机&#xff0c;DVD&#xff0c;U盘等 2&#xff1a;视频处理器——通过 HDMI/DVI/网口接收来自视频源的…

Tensorboard中常用的函数和类

常用函数 ①tf.summary.scalar 用于汇总标量数据,共有四个参数,格式如下: tf.summary.scalar(tags,values,collections None,name None) 例如:tf.summary.scalar(test,test) 以标量的形式显示变量test的变化。该函数一般用于表示损失值、准确率的变化情况。 ②tf.summary.h…

开利网络受邀参与生态合作伙伴和合控股“数利丰”品牌营销会议

近日&#xff0c;开利网络受邀出席生态合作伙伴“数利丰”品牌营销会议&#xff0c;就“数利丰”产品的技术能力和案例沉淀进行分享。 作为“数利丰”项目的技术支持方&#xff0c;开利网络创始人付立军在分享会上表示&#xff0c;现如今&#xff0c;每个企业都至少做过一套系统…