提示词能力
当您第一次开始使用 Mistral 模型时,您的首次交互将围绕提示词展开。编写有效提示词的艺术对于从 Mistral 模型或其他大型语言模型生成理想的响应至关重要。本指南将通过示例提示词向您展示四种不同的提示词能力
- 分类
- 摘要
- 个性化
- 评估
分类
Mistral 模型可以轻松地将文本**分类**到不同的类别中。以银行的客户支持机器人为例:我们可以在提示词中建立一系列预设类别,然后指示 Mistral AI 模型据此对客户的问题进行分类。
在下面的示例中,当收到客户的询问时,Mistral AI 模型将其正确分类为“国家支持”
用户 | 我想咨询一下你们的银行卡在欧盟是否可用,因为我是法国居民,对使用你们的卡很感兴趣。 |
助手 | 国家支持 |
提示词
You are a bank customer service bot. Your task is to assess customer intent and categorize customer inquiry after <<<>>> into one of the following predefined categories:
card arrival
change pin
exchange rate
country support
cancel transfer
charge dispute
If the text doesn't fit into any of the above categories, classify it as:
customer service
You will only respond with the category. Do not include the word "Category". Do not provide explanations or notes.
####
Here are some examples:
Inquiry: How do I know if I will get my card, or if it is lost? I am concerned about the delivery process and would like to ensure that I will receive my card as expected. Could you please provide information about the tracking process for my card, or confirm if there are any indicators to identify if the card has been lost during delivery?
Category: card arrival
Inquiry: I am planning an international trip to Paris and would like to inquire about the current exchange rates for Euros as well as any associated fees for foreign transactions.
Category: exchange rate
Inquiry: What countries are getting support? I will be traveling and living abroad for an extended period of time, specifically in France and Germany, and would appreciate any information regarding compatibility and functionality in these regions.
Category: country support
Inquiry: Can I get help starting my computer? I am having difficulty starting my computer,and would appreciate your expertise in helping me troubleshoot the issue.
Category: customer service
###
<<<
Inquiry: {insert inquiry text here}
>>>
我们使用的策略:
- 小样本学习:小样本学习或情境学习是指我们在提示词中提供少量示例,然后大型语言模型可以根据这些示例演示生成相应的输出。小样本学习通常可以提高模型性能,尤其是在任务困难或我们希望模型以特定方式响应时。
- 分隔符:像
###
、<<< >>>
这样的分隔符用于指定文本不同部分之间的边界。在我们的示例中,我们使用###
来表示示例,使用<<<>>>
来表示客户询问。 - 角色扮演:为大型语言模型提供一个角色(例如,“您是一个银行客户服务机器人。”)可以为模型添加个性化上下文,通常会带来更好的性能。
摘要
摘要是大型语言模型的常见任务,因为它们具有自然语言理解和生成能力。这里有一个我们可以用来生成关于一篇论文的有趣问题并总结该论文的示例提示词。
提示词
You are a commentator. Your task is to write a report on an essay.
When presented with the essay, come up with interesting questions to ask, and answer each question.
Afterward, combine all the information and write a report in the markdown format.
# Essay:
{essay}
# Instructions:
## Summarize:
In clear and concise language, summarize the key points and themes presented in the essay.
## Interesting Questions:
Generate three distinct and thought-provoking questions that can be asked about the content of the essay. For each question:
- After "Q: ", describe the problem
- After "A: ", provide a detailed explanation of the problem addressed in the question.
- Enclose the ultimate answer in <>.
## Write a report
Using the essay summary and the answers to the interesting questions, create a comprehensive report in Markdown format.
我们使用的策略:
- 分步说明:这个策略受到思维链提示的启发,它使大型语言模型能够使用一系列中间推理步骤来处理复杂任务。将复杂问题分解为更简单、更小的步骤通常更容易解决,也更容易调试和检查模型行为。在我们的示例中,我们将任务分解为三个步骤:总结、生成有趣的问题和撰写报告。这有助于语言模型在每个步骤中进行思考,并生成更全面的最终报告。
- 示例生成:我们可以要求大型语言模型通过生成带有解释和步骤的示例来自动指导推理和理解过程。在这个示例中,我们要求大型语言模型生成三个问题并提供每个问题的详细解释。
- 输出格式化:我们可以通过直接要求“以 Markdown 格式撰写报告”来要求大型语言模型以特定格式输出。
个性化
大型语言模型擅长个性化任务,因为它们可以提供与个人用户紧密相关的内容。在这个示例中,我们创建个性化的电子邮件回复来处理客户问题。
用户 | 尊敬的抵押贷款机构, 请问你们30年期固定利率的年利率(APR)是多少?与15年期固定利率相比如何? 此致, Anna |
助手 | 尊敬的 Anna, |
提示词
You are a mortgage lender customer service bot, and your task is to create personalized email responses to address customer questions. Answer the customer's inquiry using the provided facts below. Ensure that your response is clear, concise, and directly addresses the customer's question. Address the customer in a friendly and professional manner. Sign the email with "Lender Customer Support."
# Facts
30-year fixed-rate: interest rate 6.403%, APR 6.484%
20-year fixed-rate: interest rate 6.329%, APR 6.429%
15-year fixed-rate: interest rate 5.705%, APR 5.848%
10-year fixed-rate: interest rate 5.500%, APR 5.720%
7-year ARM: interest rate 7.011%, APR 7.660%
5-year ARM: interest rate 6.880%, APR 7.754%
3-year ARM: interest rate 6.125%, APR 7.204%
30-year fixed-rate FHA: interest rate 5.527%, APR 6.316%
30-year fixed-rate VA: interest rate 5.684%, APR 6.062%
# Email
{insert customer email here}
我们使用的策略:
- 提供事实:将事实纳入提示词对于开发客户支持机器人非常有用。在呈现这些事实时,使用清晰简洁的语言非常重要。这有助于大型语言模型对客户查询提供准确快速的响应。
评估
评估大型语言模型输出的方法有很多。以下是三种供您参考的方法:包含置信度分数、引入评估步骤或使用另一个大型语言模型进行评估。
包含置信度分数
我们可以在生成的输出中包含一个置信度分数。
助手 |
|
提示词
You are a summarization system that can provide summaries with associated confidence scores.
In clear and concise language, provide three short summaries of the following essay, along with their confidence scores.
You will only respond with a JSON object with the key Summary and Confidence. Do not provide explanations.
# Essay:
{insert essay text here}
我们使用的策略:
- JSON 输出:为了方便下游任务,通常首选 JSON 格式输出。我们可以通过将 response_format 设置为
{"type": "json_object"}
来启用 JSON 模式,并在提示词中指定“您将仅回复一个包含 Summary 和 Confidence 键的 JSON 对象。” 在 JSON 对象中指定这些键有助于提高清晰度和一致性。 - 更高的 Temperature:在这个示例中,我们提高了 temperature 值,以鼓励模型更具创造力,并输出三个彼此不同的生成摘要。
引入评估步骤
我们还可以在提示词中添加第二个评估步骤。我们要求大型语言模型生成三个摘要并评估这三个摘要。
助手 |
|
提示词
You are given an essay text and need to provide summaries and evaluate them.
# Essay:
{insert essay text here}
Step 1: In this step, provide three short summaries of the given essay. Each summary should be clear, concise, and capture the key points of the speech. Aim for around 2-3 sentences for each summary.
Step 2: Evaluate the three summaries from Step 1 and rate which one you believe is the best. Explain your choice by pointing out specific reasons such as clarity, completeness, and relevance to the speech content.
使用另一个大型语言模型进行评估
在生产系统中,通常使用另一个大型语言模型进行评估,以便将评估步骤与摘要生成分开。
- 步骤 1:使用第一个大型语言模型生成三个摘要
助手 |
|
提示词
Provide three short summaries of the given essay. Each summary should be clear, concise, and capture the key points of the essay.
Aim for around 2-3 sentences for each summary.
# essay:
{insert essay text here}
- 步骤 2:使用另一个大型语言模型对生成的摘要进行评分
助手 |
|
提示词
You are given an essay and three summaries of the essay. Evaluate the three summaries and rate which one you believe is the best.
Explain your choice by pointing out specific reasons such as clarity, completeness, and relevance to the essay content.
# Essay:
{insert essay text here}
# Summaries
{insert the previous output}
我们使用的策略:
- 大型语言模型链:在这个示例中,我们将两个大型语言模型按顺序串联起来,第一个大型语言模型的输出作为第二个大型语言模型的输入。大型语言模型链的方法可以根据您的特定用例进行调整。例如,您可以选择串联三个大型语言模型,其中两个大型语言模型的输出汇入第三个大型语言模型。虽然大型语言模型链提供了灵活性,但重要的是要注意,它可能会导致额外的 API 调用和潜在的成本增加。