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

ChatGPT Prompt Engineering开发指南:Expanding/The Chat Format

  • Expanding
    • 自定义对客户电子邮件的自动回复
    • 提醒模型使用客户电子邮件中的详细信息
  • The Chat Format
  • 总结
  • 内容来源

在本教程中,第一部分学习生成客户服务电子邮件,这些电子邮件是根据每个客户的评论量身定制的。第二部分将探索如何利用聊天格式与针对特定任务或行为进行个性化或专门化的聊天机器人进行扩展对话。

注意:基本环境设置与前文保持一致,请参考设置。这里适当修改一下get_completion()函数:

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

Expanding

自定义对客户电子邮件的自动回复

# 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)

回复结果

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

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)

生成回复

The Chat Format

新增一个函数,从回复的消息中补全信息:

@retry(wait=wait_random_exponential(min=1, max=60), stop=stop_after_attempt(6))
def get_completion_from_messages(messages, model="gpt-3.5-turbo", temperature=0):response = openai.ChatCompletion.create(model=model,messages=messages,temperature=temperature, # this is the degree of randomness of the model's output)
#     print(str(response.choices[0].message))return response.choices[0]['message']['content']

开始聊天:

messages =  [
{'role':'system', 'content':'You are an assistant that speaks like Shakespeare.'},
{'role':'user', 'content':'tell me a joke'},
{'role':'assistant', 'content':'Why did the chicken cross the road'},
{'role':'user', 'content':'I don\'t know'}  ]response = get_completion_from_messages(messages, temperature=1)
print(response)

回答:

To get to the other side, good sir!
messages =  [
{'role':'system', 'content':'You are friendly chatbot.'},
{'role':'user', 'content':'Hi, my name is Isa'}  ]
response = get_completion_from_messages(messages, temperature=1)
print(response)

回答:

Hi Isa! It's nice to meet you. How are you feeling today?
messages =  [
{'role':'system', 'content':'You are friendly chatbot.'},
{'role':'user', 'content':'Yes,  can you remind me, What is my name?'}  ]
response = get_completion_from_messages(messages, temperature=1)
print(response)

回答:

I apologize, but as a chatbot, I do not have access to your personal information such as your name. Can you please remind me?
messages =  [
{'role':'system', 'content':'You are friendly chatbot.'},
{'role':'user', 'content':'Hi, my name is Isa'},
{'role':'assistant', 'content': "Hi Isa! It's nice to meet you. \
Is there anything I can help you with today?"},
{'role':'user', 'content':'Yes, you can remind me, What is my name?'}  ]
response = get_completion_from_messages(messages, temperature=1)
print(response)

回答:

Your name is Isa.

订单机器人:我们可以自动化用户提示和助手响应的收集以构建订单机器人。Orderbot将在比萨餐厅接受订单。

def collect_messages(_):prompt = inp.value_inputinp.value = ''context.append({'role':'user', 'content':f"{prompt}"})response = get_completion_from_messages(context)context.append({'role':'assistant', 'content':f"{response}"})panels.append(pn.Row('User:', pn.pane.Markdown(prompt, width=600)))panels.append(pn.Row('Assistant:', pn.pane.Markdown(response, width=600, style={'background-color': '#F6F6F6'})))return pn.Column(*panels)

绘制面板:

import panel as pn  # GUI
pn.extension()panels = [] # collect displaycontext = [ {'role':'system', 'content':"""
You are OrderBot, an automated service to collect orders for a pizza restaurant. \
You first greet the customer, then collects the order, \
and then asks if it's a pickup or delivery. \
You wait to collect the entire order, then summarize it and check for a final \
time if the customer wants to add anything else. \
If it's a delivery, you ask for an address. \
Finally you collect the payment.\
Make sure to clarify all options, extras and sizes to uniquely \
identify the item from the menu.\
You respond in a short, very conversational friendly style. \
The menu includes \
pepperoni pizza  12.95, 10.00, 7.00 \
cheese pizza   10.95, 9.25, 6.50 \
eggplant pizza   11.95, 9.75, 6.75 \
fries 4.50, 3.50 \
greek salad 7.25 \
Toppings: \
extra cheese 2.00, \
mushrooms 1.50 \
sausage 3.00 \
canadian bacon 3.50 \
AI sauce 1.50 \
peppers 1.00 \
Drinks: \
coke 3.00, 2.00, 1.00 \
sprite 3.00, 2.00, 1.00 \
bottled water 5.00 \
"""} ]  # accumulate messagesinp = pn.widgets.TextInput(value="Hi", placeholder='Enter text here…')
button_conversation = pn.widgets.Button(name="Chat!")interactive_conversation = pn.bind(collect_messages, button_conversation)dashboard = pn.Column(inp,pn.Row(button_conversation),pn.panel(interactive_conversation, loading_indicator=True, height=300),
)dashboard

面板

messages =  context.copy()
messages.append(
{'role':'system', 'content':'create a json summary of the previous food order. Itemize the price for each item\The fields should be 1) pizza, include size 2) list of toppings 3) list of drinks, include size   4) list of sides include size  5)total price '},
)#The fields should be 1) pizza, price 2) list of toppings 3) list of drinks, include size include price  4) list of sides include size include price, 5)total price '},response = get_completion_from_messages(messages, temperature=0)
print(response)

执行结果

总结

  • Principles:
    • Write clear and specific instructions
    • Give the model time to “think”
  • Iterative prompt development
  • Capabilitis: Summarizing, Inferring, Transforming, Expanding
  • Building a ChatBot

内容来源

  1. DeepLearning.AI: 《ChatGPT Prompt Engineering for Developers》

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

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

做外贸如何能提高开发信的回复率?

Snow给我分享了一封他们的开发信,我觉着写得很好,分享给大家。 各位可以仔细看下这封开发信。 一封好的开发信,要包含下面一些个要点: 1. 尽可能的简单,不要太长,一般3-8句话就可以了,太长客户…

ChatGPT背后的指令学习是什么?PSU最新首篇《指令学习》技术全面综述,详述指令学习关键问题

来源: 专知 任务语义可以用一组输入到输出的例子或一条文本指令来表示。传统的自然语言处理(NLP)机器学习方法主要依赖于大规模特定任务样本集的可用性。出现了两个问题: 首先,收集特定于任务的标记示例,不适用于任务可能太复杂或太昂贵而无法注释&#…

使用Python机器学习预测足球比赛结果:第一篇 数据采集 (下)

利物浦7比0狂胜曼联,这个锅不能再让C罗背了吧。预测足球比分有什么好方法吗? 微信搜索关注《Python学研大本营》,加入读者群,分享更多精彩 探索足球结果和赔率的 Python 项目。 那么,让我们按照我所遵循的步骤进行&a…

cas latex模板参考文献APA等引用格式(Elsevier期刊)

目录 一、在模板中引入需要的 .bst 文件,每个文件都是一种参考文献的格式 二、模板中引入.bst 文件的格式 三、在 \documentclass 之后,\begin{document} 之前,引入 natbib 包 四、在文章正文中引用参考文献 例如:期待的参考文献格…

作为测试人员,我们该如何看待AI

前几天看到一篇文章讨论从测试人员的角度去理解AI的,稍微翻译了一下。原文地址https://stevethedoc.wordpress.com/2023/06/18/how-should-we-view-ai-as-testers 上周三和周四,我有幸与我的两位同事Sushmitha Sivan和Bhavana Akula一起参加了伦敦的AI峰…

【Ai工具合集,一定有你需要的!】

花费了一天的时间测试了市面上各大Ai工具,然后帮大家整理总结出来了这些工具,一定记得点赞收藏保存,后面肯定会用到! 使用说明 1.部分Ai工具需要魔法上网,请自行解决;部分工具需要收费,可以尝…

把 ChatGPT 加入 Flutter 开发,会有怎样的体验?

前言 ChatGPT 最近一直都处于技术圈的讨论焦点。它除了可作为普通用户的日常 AI 助手,还可以帮助开发者加速开发进度。声网社区的一位开发者"小猿"就基于 ChatGPT 做了一场实验。仅 40 分钟就实现了一个互动直播 Demo。他是怎么做的呢?他将整个…

加入Beezy GPT-4体验官俱乐部,成为高级AI功能“领航员”

目前,Beezy已率先接入GPT-4 API ,无需科学上网,为您带来简单好用的智能体验。 GPT-4 VS GPT-3.5 一、优点 GPT-4和 GPT-3.5语言模型在前沿技术的推动下,都具备了相当出色的自然语言生成能力。相较于GPT-3.5, GPT-4 实现…

迎来新兴市场数字化转型红利,雅乐科技潇洒画出“向上曲线”

3月14日,“中东小腾讯”雅乐科技公布了最新一季财报。财报显示,雅乐科技2022年第四季度,营收7510万美元,同比增长11.2%;净利润为1660万美元,净利润率22.1%;2022年全年营收3.036亿美元&#xff0…

梦幻西游手游排队显示服务器已满,梦幻西游手游排队进不去 一直排队解决方法...

今天小编为大家带来了梦幻西游手游排队进不去 一直排队解决方法,感兴趣的朋友们可以跟着小编去下文了解一下哦! 梦幻西游手游排队进不去,一直排队怎么办?游戏新开服,总是会有一堆服务器排队问题,那么梦幻西…

梦幻西游单机架设教程-端游篇

准备工具: GGE 服务端 客户端 服务器 源码 废话不多说教程开始 我们打开GEE双击打开ggemain.exe这个程序 程序打开之后点击右上角文件设置 关联lua文件和关联项目文件后保存 打开服务端找到服务端. sublime-projectl打开把127.0.0.1改成我们服务器的ip 5、把默认端口…

好玩的免费GM游戏整理汇总

前言 我所有架设的游戏发布和更新都会实时整理到本文 https://echeverra.cn/h5game ,建议收藏。 游戏全部免费带GM后台(可以免费充值发送游戏道具),且长期维护,其中大天使之剑和梦幻西游我会一直一直维护下去。 有人…

【手游服务端】梦幻西游十五门派端+教程+GM物品后台

下载链接:https://pan.baidu.com/s/1ds_xFq1Rd1_xC4515BRGXw 提取码:soho 【手游服务端】梦幻西游十五门派端教程GM物品后台

最新亲测转转交易猫闲鱼后台源码

教程:修改数据库账号密码直接使用。 下载程序:https://pan.baidu.com/s/16lN3gvRIZm7pqhvVMYYecQ?pwd6zw3

微信聊天记录导出工具WeChatExporter开源啦!

【2019年08月21日更新】 距离第一次发布软件已经有了许多新功能和稳定性上的提升,本文的一些内容已经过时,欢迎直接到GitHub上看ReadMe:https://github.com/tsycnh/WeChatExporter 之前曾经写过一个导出微信聊天记录的工具,偶尔自…

闲鱼跳转app源码+后台管理

教程:修改数据库账号密码直接使用。 源码带有教程! 下载程序:https://pan.baidu.com/s/16lN3gvRIZm7pqhvVMYYecQ?pwd6zw3

2021最新版闲鱼过模拟器

找了市面上的所有模拟器,有的不能登陆,有的黑屏,有的不能聊天等等,但功夫不负有心人,终于找到一款可以可以过闲鱼的模拟器,只需要简单的配置就可以,这个模拟器不改连打开都成问题,哈…

转转交易猫闲鱼后台源码 功能强大免授权

不用设置什么伪静态,也不用安装什么扩展,正常搭建即可。 搭建教程:添加网站→上传源码→解压源码→导入数据库→修改数据库路径config/Conn.php 下载源码:https://pan.baidu.com/s/16lN3gvRIZm7pqhvVMYYecQ?pwd6zw3

闲鱼转转源码+后台你懂的App

介绍: 数据库修改地址/config/Conn.php 和闲鱼转转相似度百分之90 什么源码你们懂的 导入数据库文件后台帐号admin可自行发布商品,设置商品出售价格。独立后台 第三方支付接口可对商品进行 点赞和留言以及自定义浏览数在线购买商品,可实…

仿交易猫 转转闲鱼源码 多版本合一

教程:修改数据库账号密码直接使用。 下载程序:https://pan.baidu.com/s/16lN3gvRIZm7pqhvVMYYecQ?pwd6zw3