ChatGPT提示词工程(六):Expanding扩展

news/2024/5/19 19:22:10 标签: chatgpt, prompt, openai, 人工智能, AI

目录

  • 一、说明
  • 二、安装环境
  • 三、扩展(Expanding)
    • 1. 自定义自动回复客户电子邮件
    • 2. 提醒模型使用客户电子邮件中的详细信息
    • 3. 参数 temperature

一、说明

这是吴恩达 《ChatGPT Prompt Engineering for Developers》 的课程笔记系列。
本文是第六讲的内容:Transforming

二、安装环境

参考: ChatGPT提示词工程(一):Guidelines准则 的第二节
不过本节课中的辅助函数不一样了,增加了一个参数 temperature

def get_completion(prompt, model="gpt-3.5-turbo", temperature=0): # Andrew mentioned that the prompt/ completion paradigm is preferable for this class
    messages = [{"role": "user", "content": prompt}]
    response = AI.html" title=openai>openai.ChatCompletion.create(
        model=model,
        messages=messages,
        temperature=temperature, # this is the degree of randomness of the model's output
    )
    return response.choices[0].message["content"]

三、扩展(Expanding)

1. 自定义自动回复客户电子邮件

# given the sentiment from the lesson on "inferring",
# and the original customer message, customize the email
sentiment = "negative"

# review for a blender
review = f"""
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.
"""
prompt = f"""
You are a customer service AI assistant.
Your task is to send an email reply to a valued customer.
Given the customer email delimited by ```, \
Generate a reply to thank the customer for their review.
If the sentiment is positive or neutral, thank them for \
their review.
If the sentiment is negative, apologize and suggest that \
they can reach out to customer service. 
Make sure to use specific details from the review.
Write in a concise and professional tone.
Sign the email as `AI customer agent`.
Customer review: ```{review}```
Review sentiment: {sentiment}
"""
response = get_completion(prompt)
print(response)

客户邮件内容review翻译成中文为:

所以,在11月份,他们仍然有17件制的季节性销售,售价约为49美元,大约减半,但由于某种原因(称之为价格欺诈),在12月的第二周左右,同一种制的价格都上涨到了大约70美元到89美元之间。11件套的售价也比早先29美元的售价上涨了10美元左右。所以看起来还可以,但如果你看看底座,刀片锁定的部分看起来不像几年前的前几版那么好,但我计划对它非常温和(例如,我先在搅拌器里粉碎非常硬的东西,比如豆子、冰、大米等,然后在搅拌器里把它们粉碎成我想要的服务大小,然后切换到搅拌刀片,以获得更好的面粉,在做奶昔时首先使用横切刀片,如果我需要它们更细/更少浆状的话,再使用扁平刀片)。做冰沙时,要特别注意切开和冷冻水果和蔬菜(如果用菠菜–轻轻炖菠菜,让菠菜变软,然后冷冻,直到可以使用–如果做冰糕,用中小型食品加工机),这样你就可以避免在做冰沙时添加太多的冰。大约一年后,马达发出了奇怪的声音。我给客服打了电话,但保修期已经过了,所以我不得不再买一台。仅供参考:这些类型的产品已经实现了整体质量,所以他们在某种程度上依赖于品牌认知度和消费者忠诚度来维持销售。大约两天后就拿到了。

prompt
你是一名客服人工智能助理。
你的任务是向重要客户发送电子邮件回复。
鉴于客户电子邮件由```分隔,
生成回复以感谢客户的评价。
如果情绪是积极的或中性的,感谢他们的评价。
如果情绪是负面的,道歉,并建议他们可以联系到客户服务。
确保使用评价中的具体细节。
用简洁和专业的语气写作。
用“AI customer agent”签名

运行结果:
在这里插入图片描述

上述代码中,sentiment = “negative” 是写死的, 我们可以运用上一课所学(Inferring),让它自己判断客户评价的情绪

prompt = f"""
You are a customer service AI assistant.
Your task is to send an email reply to a valued customer.
Given the customer email delimited by ```, \
Generate a reply to thank the customer for their review.
What is the sentiment of their review, 
which is delimited with triple backticks?
If the sentiment is positive or neutral, thank them for \
their review.
If the sentiment is negative, apologize and suggest that \
they can reach out to customer service. 
Make sure to use specific details from the review.
Write in a concise and professional tone.
Sign the email as `AI customer agent`.
Customer review: ```{review}```
"""
response = get_completion(prompt)
print(response)

prompt:添加了一句:
What is the sentiment of their review,
which is delimited with triple backticks?

运行结果:
在这里插入图片描述

2. 提醒模型使用客户电子邮件中的详细信息

prompt = f"""
You are a customer service AI assistant.
Your task is to send an email reply to a valued customer.
Given the customer email delimited by ```, \
Generate a reply to thank the customer for their review.
If the sentiment is positive or neutral, thank them for \
their review.
If the sentiment is negative, apologize and suggest that \
they can reach out to customer service. 
Make sure to use specific details from the review.
Write in a concise and professional tone.
Sign the email as `AI customer agent`.
Customer review: ```{review}```
Review sentiment: {sentiment}
"""
response = get_completion(prompt, temperature=0.7)
print(response)

prompt:添加了一句 Make sure to use specific details from the review.
get_completion参数temperature允许你改变模型的探索和多样性的程度
运行结果:
在这里插入图片描述

3. 参数 temperature

在这里插入图片描述
参数temperature能使我们改变模型响应的多样性。
比如,我最喜欢的食物,模型预测pizza可能性为53%,sushi的可能性为30%,tacos的可能性为5%
如果temperature = 0 则模型总是给出pizza
如果 temperature > 0 则模型给出的结果可能就会是 sushi 或者 tacos

https://blog.csdn.net/Jay_Xio/article/details/130460267




http://www.niftyadmin.cn/n/281756.html

相关文章

【ARMv8 编程】A64 内存访问指令——内存存储指令

在内存加载一节中实际上已经使用了内存存储指令了&#xff0c;内存存储指令将寄存器的值存储到内存中。 同样&#xff0c;Store 指令的一般形式如下&#xff1a; STR Rn, <addr> 还有 unscaled-offset 偏移形式&#xff0c;例如 STUR<type>。 程序员通常不需要明…

4.1 指令系统的发展与性能要求

学习目标&#xff1a; 指令系统的发展与性能要求的学习目标&#xff1a; 理解指令系统的发展历程&#xff0c;包括CISC、RISC、VLIW等架构的特点、优缺点以及应用领域&#xff1b;掌握指令系统的性能要求&#xff0c;包括指令集的多样性、可编程性、并行性、效率、可靠性等&a…

微信小程序学习实录2(下拉刷新、下拉加载更多、小程序事件、PHP后端代码、刷新无数据解决方案)

微信小程序学习实录2 一、全局配置1.启用lazyCodeLoading2.启用enablePullDownRefresh 二、设置全局变量三、页面初始化数据四、当前页面进入执行下拉刷新五、监听用户下拉动作六、页面上拉触底事件的处理函数七、PHP后端对接API八、常见问题1.不显示下拉加载...2.下拉不刷新数…

python人工智能【隔空手势控制鼠标】“解放双手“

大家好&#xff0c;我是csdn的博主&#xff1a;lqj_本人 这是我的个人博客主页&#xff1a; lqj_本人的博客_CSDN博客-微信小程序,前端,python领域博主lqj_本人擅长微信小程序,前端,python,等方面的知识https://blog.csdn.net/lbcyllqj?spm1011.2415.3001.5343哔哩哔哩欢迎关注…

二十五、OSPF高级技术——开销值、虚链路、邻居建立、LSA、静默接口

文章目录 调试指令&#xff08;三张表&#xff09;1、邻居表&#xff1a;dis ospf peer brief2、拓扑表&#xff08;链路状态数据库&#xff09;&#xff1a;dis ospf lsdb3、路由表&#xff1a;dis ip routing-table 一、OSPF 开销值/度量值&#xff08;cost&#xff09;1、co…

JetBrains 公布 WebStorm 2023.2 路线图

JetBrains 已公布了 WebStorm 2023.2 版本的路线图&#xff0c;以便用户可以率先了解到官方的规划以及能够预览一下未来能够用上的新功能。 主要聚焦于以下内容&#xff1a; 稳定的新 UI。这是此版本中的优先事项之一。CSS 嵌套支持。WebStorm 2023.2 计划将添加对 CSS 嵌套功能…

PMP/高项 05-项目进度管理

项目进度管理 概念 项目进度管理&#xff08;Schedule Management) 项目进度管理又叫项目工期管理&#xff08;Duration Management)或项目的时间管理(Time Management) 是一种为管理项目按时完成项目所需的各个过程 进度管理过程 规划进度管理 定义活动 排列活动顺序 估算活…

Ubuntu下跑通 nnUNet v2

网上关于nnUNet运行的教程大部分是针对nnUNet v1的。但由于nnUNet v2已经推出&#xff0c;而且相对于v1有了很大的更新。所以个人只能啃nnUNet的英文文档参考在Windows上实现nnU-Net v2的环境配置_netv2_无聊的程序猿的博客-CSDN博客 实现了代码的复现。 1.System requirement…