【Prompting】ChatGPT Prompt Engineering开发指南(3)

news2024/11/24 7:20:20

ChatGPT Prompt Engineering开发指南3

  • 总结文字
    • 使用单词/句子/字符限制进行总结
    • 以运输和交付为重点进行总结
    • 以价格和价值为重点进行总结
  • 尝试“extract”而不是“summarize”
  • 总结多个产品评论
  • 内容来源

本文承接上文:ChatGPT Prompt Engineering开发指南2,继续基于Deeplearning.AI的ChatGPT Prompt Engineering for Developers学习。在本教程中,将以特定主题的重点进行总结文本。

总结文字

prod_review = """
Got this panda plush toy for my daughter's birthday, \
who loves it and takes it everywhere. It's soft and \ 
super cute, and its face has a friendly look. It's \ 
a bit small for what I paid though. I think there \ 
might be other options that are bigger for the \ 
same price. It arrived a day earlier than expected, \ 
so I got to play with it myself before I gave it \ 
to her.
"""

使用单词/句子/字符限制进行总结

prompt = f"""
Your task is to generate a short summary of a product \
review from an ecommerce site. 

Summarize the review below, delimited by triple 
backticks, in at most 30 words. 

Review: ```{prod_review}```
"""

response = get_completion(prompt)
print(response)

执行结果:

Soft and cute panda plush toy loved by daughter, but a bit small for the price. Arrived early.

以运输和交付为重点进行总结

prompt = f"""
Your task is to generate a short summary of a product \
review from an ecommerce site to give feedback to the \
Shipping deparmtment.

Summarize the review below, delimited by triple
backticks, in at most 30 words, and focusing on any aspects \
that mention shipping and delivery of the product.

Review: ```{prod_review}```
"""

response = get_completion(prompt)
print(response)

执行结果:

The panda plush toy arrived a day earlier than expected, but the customer thinks it's a bit small for the price paid.

以价格和价值为重点进行总结

prompt = f"""
Your task is to generate a short summary of a product \
review from an ecommerce site to give feedback to the \
pricing deparmtment, responsible for determining the \
price of the product.  

Summarize the review below, delimited by triple 
backticks, in at most 30 words, and focusing on any aspects \
that are relevant to the price and perceived value. 

Review: ```{prod_review}```
"""

response = get_completion(prompt)
print(response)

执行结果:

Soft and cute panda plush toy, loved by daughter. However, a bit small for the price paid. Consider offering bigger options for the same price.

注意:摘要包括与重点主题无关的主题。

尝试“extract”而不是“summarize”

prompt = f"""
Your task is to extract relevant information from \ 
a product review from an ecommerce site to give \
feedback to the Shipping department. 

From the review below, delimited by triple quotes \
extract the information relevant to shipping and \ 
delivery. Limit to 30 words. 

Review: ```{prod_review}```
"""

response = get_completion(prompt)
print(response)

执行结果:

The product arrived a day earlier than expected.

总结多个产品评论

review_1 = prod_review

# review for a standing lamp
review_2 = """
Needed a nice lamp for my bedroom, and this one \
had additional storage and not too high of a price \
point. Got it fast - arrived in 2 days. The string \
to the lamp broke during the transit and the company \
happily sent over a new one. Came within a few days \
as well. It was easy to put together. Then I had a \
missing part, so I contacted their support and they \
very quickly got me the missing piece! Seems to me \
to be a great company that cares about their customers \
and products.
"""

# review for an electric toothbrush
review_3 = """
My dental hygienist recommended an electric toothbrush, \
which is why I got this. The battery life seems to be \
pretty impressive so far. After initial charging and \
leaving the charger plugged in for the first week to \
condition the battery, I've unplugged the charger and \
been using it for twice daily brushing for the last \
3 weeks all on the same charge. But the toothbrush head \
is too small. I’ve seen baby toothbrushes bigger than \
this one. I wish the head was bigger with different \
length bristles to get between teeth better because \
this one doesn’t.  Overall if you can get this one \
around the $50 mark, it's a good deal. The manufactuer's \
replacements heads are pretty expensive, but you can \
get generic ones that're more reasonably priced. This \
toothbrush makes me feel like I've been to the dentist \
every day. My teeth feel sparkly clean!
"""

# review for a blender
review_4 = """
So, they still had the 17 piece system on seasonal \
sale for around $49 in the month of November, about \
half off, but for some reason (call it price gouging) \
around the second week of December the prices all went \
up to about anywhere from between $70-$89 for the same \
system. And the 11 piece system went up around $10 or \
so in price also from the earlier sale price of $29. \
So it looks okay, but if you look at the base, the part \
where the blade locks into place doesn’t look as good \
as in previous editions from a few years ago, but I \
plan to be very gentle with it (example, I crush \
very hard items like beans, ice, rice, etc. in the \
blender first then pulverize them in the serving size \
I want in the blender then switch to the whipping \
blade for a finer flour, and use the cross cutting blade \
first when making smoothies, then use the flat blade \
if I need them finer/less pulpy). Special tip when making \
smoothies, finely cut and freeze the fruits and \
vegetables (if using spinach-lightly stew soften the \
spinach then freeze until ready for use-and if making \
sorbet, use a small to medium sized food processor) \
that you plan to use that way you can avoid adding so \
much ice if at all-when making your smoothie. \
After about a year, the motor was making a funny noise. \
I called customer service but the warranty expired \
already, so I had to buy another one. FYI: The overall \
quality has gone done in these types of products, so \
they are kind of counting on brand recognition and \
consumer loyalty to maintain sales. Got it in about \
two days.
"""

reviews = [review_1, review_2, review_3, review_4]

循环遍历代码:

for i in range(len(reviews)):
    prompt = f"""
    Your task is to generate a short summary of a product \
    review from an ecommerce site.

    Summarize the review below, delimited by triple \
    backticks in at most 20 words.

    Review: ```{reviews[i]}```
    """

    response = get_completion(prompt)
    print(i, response, "\n")

执行结果
解决办法,增加重试次数:
安装tenacity包,然后给的自己的脚本,访问API那段函数,添加修饰:@retry(wait=wait_random_exponential(min=1, max=60), stop=stop_after_attempt(6))如下:

from tenacity import (
    retry,
    stop_after_attempt,
    wait_random_exponential,
)  # for exponential backoff

@retry(wait=wait_random_exponential(min=1, max=60), stop=stop_after_attempt(6))
def get_completion(prompt, model="gpt-3.5-turbo"):
    messages = [{'role': 'user', 'content': prompt}]
    response = openai.ChatCompletion.create(
        model=model,
        messages=messages,
        max_tokens=1024,
        n=1,
        temperature=0,  # this is the degree of randomness of the model's output
        stop=None,
        top_p=1,
        frequency_penalty=0.0,
        presence_penalty=0.6,
    )
    return response['choices'][0]['message']['content']

这样的话,在访问之间会自动增加一定时间间隔,并在访问受拒之后,再次进行尝试。
重新执行上述代码,返回结果如下:
执行结果

内容来源

  1. DeepLearning.AI: 《ChatGPT Prompt Engineering for Developers》
  2. openai.error.RateLimitError: Rate limit reached for default-text-davinci-003 in organization

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

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

相关文章

RK3588平台开发系列讲解(进程篇)图解linux netlink

平台内核版本安卓版本RK3588Linux 5.10Android 12文章目录 一、netlink协议簇二、netlink初始化沉淀、分享、成长,让自己和他人都能有所收获!😄 📢 netlink 协议是一种进程间通信(Inter Process Communication,IPC)机制,为的用户空间和内核空间以及内核的某些部分之间…

解决FTD2000 麒麟系统下计算机属性中显示的内存比实际内存少

FTD2000 麒麟系统下计算机属性中显示的内存比实际内存少,首先确认问题点,判断是飞腾D2000的bios问题,还是麒麟系统问题 可以用如下方式做出判断 1、D2000 log打印进入shell 后 exit 在弹出来的界面中选 bios set 选项、进入bios 设置界面,如下图 可以看到 bios 下,Tota…

总结851

每周小结 英语背了3篇文章 高数一直刷关于一元积分的题目,一共150道左右,平均一天20道左右,强化课看到第2讲数列。 每日必复习(5分钟) 线性代数 向量组 学习内容: 暴力英语:继续背诵《The kin…

YOLOv5:解读yolo.py

YOLOv5:解读yolo.py 前言前提条件相关介绍yolo.pyparse_model()函数Detect类Model类 参考 前言 记录一下自己阅读yolo.py代码的一些重要点,方便自己查阅。特别感谢,在参考里,列举的博文链接,写得很好,对本人…

康耐视智能相机insight主从触发以及康耐视insight视觉系统之间数据特有交互方式

1、一个相机设置为主系统,指定自己的名称,下方可以指定发给从系统的数据,触发方式不要设置 成网络 2、另外一个相机触发方式设置成网络,然后下方指定主系统的名称 3、主系统每触发一次,就会带动从系统触发,同时指定的数据会发送到从系 统,从系统使用函数getstring获取…

【数据结构】图的创建和深度(DFS)广度(BFS)优先遍历

一、图 1.图的概念 图是由顶点的有穷非空集合和顶点之间边的集合组成,通过表示为G(V,E),其中,G标示一个图,V是图G中 顶点的集合,E是图G中 边的集合。 2.图的种类 图分为无向图和有向图 无向图:若顶点V…

用于OOD预测的稳定学习

当测试数据和训练数据共享相似的分布时,基于深度神经网络的方法取得了惊人的性能,但在其他情况下可能会失败。因此,消除训练和测试数据之间分布变化的影响对于构建有前景的深度模型至关重要。作者考虑了一个更具挑战性的情况。通过训练样本的…

大数据Doris(二十一):Bloom Filter索引以及Doris索引总结

文章目录 Bloom Filter索引以及Doris索引总结 一、Bloom Filter索引 1、BloomFilter索引原理 2、BloomFilter索引语法 3、注意事项 二、Doris索引总结 Bloom Filter索引以及Doris索引总结 一、Bloom Filter索引 1、BloomFilter索引原理 BloomFilter是由Bloom在1970年提…

移动机器人运动规划---基于图搜索的基础知识---广度优先遍历与深度优先遍历

移动机器人运动规划---基于图搜索的基础知识---广度优先遍历与深度优先遍历 广度优先搜索(BFS)深度优先搜索(DFS)BFS vs DFS 图搜索优化的方向就是: 按照什么规则去访问节点,按照什么规则弹出节点&#xff…

快速了解 TypeScript

目录 1、简介 2、安装TypeScript 3、编译代码 4、类型注解 5、接口 6、类 7、运行TypeScript Web应用 1、简介 TypeScript是JavaScript类型的超集,它可以编译成纯JavaScript。 TypeScript可以在任何浏览器、任何计算机和任何操作系统上运行,并且…

【哈士奇赠书活动 - 23期】-〖你好 ChatGPT〗

文章目录 ⭐️ 赠书 - 《你好 ChatGPT》⭐️ 内容简介⭐️ 作者简介⭐️ 精彩书评⭐️ 赠书活动 → 获奖名单 ⭐️ 赠书 - 《你好 ChatGPT》 ⭐️ 内容简介 人工智能(AI)时代已经来临,AIGC(人工智能生成内容)正在进一步…

【精选】各种节日祝福(C语言,可修改),Easyx图形库应用+源代码分享

博主:命运之光✨✨ 专栏:Easyx图形库应用📂 目录 ✨一、程序展示 范例一:❤新年祝福❤ 范例二:❤母亲节祝福❤ ✨二、项目环境 简单介绍一下easyx图形库应用 Easyx图形库 ✨三、运行效果展示(视频&am…

【C++起飞之路】初级——缺省参数、函数重载、引用

C:函数重载、引用 一、缺省参数🛫1.1 🚝什么是缺省参数1.2 🚝缺省参数的分类a. 全缺省参数b. 半缺省参数(部分缺省参数) 1.3 🚝注意事项 二、函数重载🛫2.1 🚝什么是函数…

时间复杂度:根号n一般来说大于log(n)

f ( x ) x − l o g 2 x f(x)\sqrt{x}-log_2 x f(x)x ​−log2​x 对这函数求导后,比较分母大小,可以得到结论 f ( x ) f(x) f(x)先减后增,分界点为 x 4 ( l n 2 ) 2 x \frac{4}{(ln2)^2} x(ln2)24​ f ( x ) f(x) f(x)的图像如下所示&a…

PPT技能之文字格式,转身的文字这样做

只要用PPT,一定需要设置文字格式。好的文字格式,给人惊艳的感觉,是一种愉悦的享受。 你的关注,是我最大的动力!你的转发,我的10W!茫茫人海有你的支持,给我无限动力。 1、字体。 按…

什么是Java中的阻塞队列?它有什么作用?

在Java中,阻塞队列是一种特殊的队列,它可以在队列为空或队列已满时阻塞添加或移除元素的操作。阻塞队列通常用于多线程编程中,可以帮助我们更加方便地进行线程通信和协作。在本文中,我将从面试的角度,详细讲解Java中的…

在线办公时代,如何选择合适的云办公软件?

文章目录 在线办公时代,如何选择合适的云办公软件?在线文档石墨文档腾讯文档飞书文档 远程控制ToDesk向日葵 会议协同腾讯会议ZOOM 总结 在线办公时代,如何选择合适的云办公软件? 随着数字经济的发展和疫情的影响,云办…

100天精通Python(可视化篇)——第87天:matplotlib绘制不同种类炫酷雷达图参数说明+代码实战(普通、堆叠、多个、矩阵、极坐标雷达图)

文章目录 专栏导读1. 雷达图1)介绍2)参数说明 2. 基本雷达图3. 堆叠雷达图4. 六边形战士5. 多个雷达图6. 雷达图矩阵7. 极坐标雷达图 专栏导读 🔥🔥本文已收录于《100天精通Python从入门到就业》:本专栏专门针对零基础…

做一名活动策划是什么体验

在一些不了解的人眼中,活动策划就是那种外表光鲜亮丽,气场十足,眼神犀利,跷着二郎腿,情绪饱满的完成一场又一场的完美的秀。 好像确实是这样,但是你们又知不知道这背后的一切我们活动策划到底付出了什么&a…

SpringMVC的三大功能

目录 一、初识SpringMVC 1.1 MVC的定义 1.2 MVC和SpringMVC的关系是什么? 1.3 SpringMVC的重要性 二、Spring MVC的三大功能 2.1 连接功能 2.1.1 RequestMapping 注解介绍 2.1.2 GetMapping 和 PostMapping 2.2 获取参数功能 2.2.1 传递普通参数 2.2.2 传递对象 2…