ChatGPT Prompting开发实战(十一)

一、根据用户评论编写prompt生成定制化的客户服务邮件

设想客户服务部门会收集很多用户针对购买的产品的使用评论,那么可以利用LLM来分析每个评论的内容所表达的是正面的反馈还是负面的反馈,然后自动生成相应的定制化的致客户的服务邮件。此外,由于LLM在语言内容生成方面存在一定的随机性,那么可以根据需要在输入模型时设置相关的参数值来控制这种随机性。

接下来会给出具体示例,通过调用模型“gpt-3.5-turbo”来演示并解析如何针对上述需求来编写相应的prompts。

二、结合案例演示解析如何使用prompt生成客户服务邮件

下面给出一段用户评论,这里跳过模型根据评论分析是正面反馈或者是负面反馈的过程,分析结果是"negative":

# 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,要求根据评论内容以及用户表达的情感倾向来生成相应的致客户的邮件。

prompt示例如下:

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)

打印输出结果如下:

Dear Valued Customer,

Thank you for taking the time to share your review with us. We appreciate your feedback and apologize for any inconvenience you may have experienced.

We are sorry to hear about the price increase you noticed in December. We strive to provide competitive pricing for our products, and we understand your frustration. If you have any further concerns regarding pricing, we recommend reaching out to our customer service team who will be happy to assist you.

We also appreciate your feedback regarding the base of the system. We continuously work to improve the quality of our products, and your comments will be taken into consideration for future enhancements.

Regarding the motor issue you encountered, we apologize for any inconvenience caused. Our customer service team is available to assist you with any technical difficulties you may encounter, even if the warranty has expired. Please do not hesitate to reach out to them for further assistance.

Thank you once again for your review. We value your loyalty and appreciate your support. If you have any further questions or concerns, please feel free to contact our customer service team.

Best regards,

AI customer agent

接下来修改prompt,在调用API时增加参数temperature的设定,目的是让模型根据设定值来差异化生成相应的内容。一般来说,这个参数值设为0表明只让模型输出一种预测结果即可,或者说想让模型输出稳定的预测结果(多次预测),但是有时候如果想看到更多的差异化的输出结果,即让模型生成内容时具有更多的随机性,那么可以把参数值设置为大于0,值越高,表示随机性越大,模型生成的内容可能会更有“创意性”。

prompt示例如下:

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.3)

print(response)

打印输出结果如下:

Dear valued customer,

Thank you for taking the time to share your review with us. We appreciate your feedback and apologize for any inconvenience you may have experienced.

We are sorry to hear about the price increase you noticed in December. We strive to offer competitive prices and provide value to our customers. We understand your concerns regarding the quality of the base and we will take this into consideration for future improvements.

We apologize for any inconvenience caused by the motor issue you encountered. Our customer service team is here to assist you, even if the warranty has expired. Please feel free to reach out to them for any further assistance or inquiries you may have.

Thank you again for your review and for choosing our products. We value your loyalty and will continue to work towards providing you with the best possible experience.

Best regards,

AI customer agent

prompt示例如下:

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)

打印输出结果如下:

Dear valued customer,

Thank you for taking the time to share your review with us. We appreciate your feedback and apologize for any inconvenience you may have experienced.

We are sorry to hear about the price increase and the decrease in the quality of the base of our 17 piece system. We understand your concerns and assure you that we take customer feedback seriously. We strive to provide the best possible products and services to our customers.

If you have any further issues or questions, we recommend reaching out to our customer service department. They will be more than happy to assist you and address any concerns you may have.

Thank you again for your review and for choosing our brand. We value your loyalty and will continue to work hard to meet your expectations.

Best regards,

AI customer agent

你可能感兴趣的:(AI,prompt,chatgpt,自然语言处理,大模型开发,人工智能)