【吴恩达】ChatGPT提示工程师 笔记【第七课Expanding 扩展】

【吴恩达】ChatGPT提示工程师  笔记【第七Expanding 扩展】

课程7视频地址

在这节课中,您将生成针对每个客户评价的定制客户服务邮件。

"扩展"是指接受较短的文本,如一组指令或一系列主题,然后让大型语言模型生成更长的文本,如邮件或关于某个主题的论文。这种用法有很多好处,比如你可以使用大型语言模型作为头脑风暴的合作伙伴。但我也想承认,这也有一些问题,如有人可能会用它产生大量垃圾信息。所以,当你使用大型语言模型的这些能力时,请只在负责任的方式,以及能帮助人们的方式中使用。在这个视频中,我们将通过一个例子来演示如何使用语言模型根据一些信息生成个性化的电子邮件。邮件自称来自一个AI bot,正如Andrew提到的,这非常重要。我们还将使用模型的另一个输入参数"温度",这样可以让你改变模型回应的探索程度和多样性。让我们开始吧!  首先,我们将进行常规的设置。安装OpenAI Python包,并定义辅助函数"get_completion"。  

现在,我们将根据客户的评论和情绪来写一个定制的电子邮件回应。我们将使用语言模型根据客户的评论和评论的情绪生成一封定制的电子邮件。我们已经使用我们在推断视频中看到的提示提取出了评论的情绪,这是一篇关于搅拌器的客户评论。  现在,我们将根据情绪定制回复。这里的指令是“你是一个客户服务AI助手。你的任务是向一位尊贵的客户发送电子邮件回复。给出由三个反引号分隔的客户电子邮件,生成一份回复,感谢客户的评论。如果情绪是积极的或中性的,感谢他们的评论。如果情绪是消极的,道歉并建议他们可以联系客户服务。一定要使用评论中的特定细节,以简洁和专业的语气写邮件,并签名为'AI客户代理'”。当你使用语言模型生成要显示给用户的文本时,非常重要的一点是要透明,让用户知道他们看到的文本是由AI生成的。  然后,我们将输入客户的评论和评论的情绪。注意,这部分并不一定重要,因为我们其实可以使用这个提示来提取评论的情绪,然后在后续步骤中写邮件。但是,为了例子的完整性,我们已经从评论中提取出了情绪。那么,这里我们有一份对客户的回复。它根据客户在评论中提到的细节进行了回复。正如我们指示的,因为这只是一个AI客户服务助手,所以建议他们联系客户服务。 

 接下来,我们将使用语言模型的一个参数"温度",这将允许我们改变模型回应的多样性。你可以把温度看作是模型的探索程度或随机性。所以对于这个特定的短语,"我最喜欢的食物是",模型预测的最可能的下一个词是"pizza",其次可能的词是"sushi"和"tacos"。所以在温度为零的情况下,模型会始终选择最可能的下一个词,也就是"pizza",在较高的温度下,它会选择不太可能的词,甚至在更高的温度下,它可能会选择"tacos",这只有5%的概率被选择。你可以想象,当模型继续生成更多的词语,这个回应——我最喜欢的食物是披萨,会与第一个回应——我最喜欢的食物是塔科,产生分歧。所以,当模型继续生成时,这两个回应会变得越来越不同。总的来说,当你想构建一个可预测的应用时,我建议使用温度为零。在所有的视频中,我们一直在使用温度为零,我认为如果你想构建一个可靠和可预测的系统,你应该选择这个。如果你想以更有创造性的方式使用模型,可能希望获得更广泛的输出,你可能想使用较高的温度。现在,让我们用刚才的提示,试着生成一封邮件,但让我们用更高的温度。在我们一直在用的"get_completion"函数中,我们定义了一个模型和一个温度,但我们设定了默认值。现在,让我们试着改变温度。  我们使用提示,然后试试温度0.7。对于温度为零的情况,每次执行相同的提示,你应该期望得到相同的完成。而对于温度0.7,你每次都会得到不同的输出。所以这里我们有我们的邮件,你可以看到,它与我们之前收到的邮件是不同的。让我们再执行一次,以显示我们会得到另一封不同的邮件。这里我们有另一封不同的邮件。所以,我建议你自己试试温度。

也许你可以现在暂停视频,试试这个提示,并使用各种不同的温度,看看输出如何变化。  总的来说,温度较高时,模型的输出更随机。你可以把它想象成,温度较高时,助手更容易分心,但可能更有创造性。在下一个视频中,我们将更多地讨论聊天完成端点格式,以及如何使用这种格式创建自定义的聊天机器人。

Setup

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",temperature=0): # Andrew mentioned that the prompt/ completion paradigm is preferable for this class
    messages = [{"role": "user", "content": prompt}]
    response = 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"]

Customize the automated reply to a customer email(定制对客户邮件的自动回复

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

Remind the model to use details from the customer's email(提醒模型使用客户电子邮件中的详细信息。

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值