使用推理进行例行生成
在开发客户服务解决方案时,初始步骤之一是将知识库文章转换为 LLM 可以理解和遵循的一组例程。在此上下文中,例程是指为 LLM 有效执行而专门设计的循序渐进的指令集。每个例程都经过精心构建,以便一个步骤对应一个清晰的操作。操作可以包括响应用户、触发函数调用或检索其他相关知识。
大多数内部知识库文章都很复杂,并且是为人类解释而设计的。它们通常包含复杂的图表、多步骤流程和决策树,这些都给基于 LLM 的解决方案带来了挑战,使其难以有意义地进行推理。通过将这些文档分解为例程,可以简化每个指令并以引导 LLM 完成一系列小型、可管理任务的方式进行格式化。这种细粒度的方法可减少歧义,使 LLM 能够有条不紊地处理信息,并降低出现幻觉或偏离预期路径的风险。
将这些知识库文章转换为例程可能非常耗时且具有挑战性,特别是对于那些试图构建自动化管道的公司而言。每个例程都必须考虑各种用户场景,其中操作需要明确定义。例如,当需要函数调用时,例程必须指定要检索的确切信息或要执行的操作——无论是触发 API、检索外部数据还是引入其他上下文。虽然使用传统的 GPT 类模型自动化此过程可以显著减少手动工作量,但它通常会带来新的挑战。一些挑战包括设计健壮的指令,使其足够具体以供 LLM 一致遵循,捕获客户互动中可能出现的独特边缘情况,提供高质量的少量示例来指导模型的行为,以及在某些情况下,微调模型以获得更可靠或更专业的成果。
o1 已证明能够零样本地有效地分解这些文章并将其转换为例程集,这意味着 LLM 可以在没有大量示例或类似任务的先前培训的情况下理解并遵循这些指令。这最大限度地减少了所需的提示工作量,因为例程结构本身为 LLM 完成每个步骤提供了必要的指导。通过将任务分解为具体操作并根据需要集成函数调用,o1 的方法确保即使是复杂的业务流程也能被 LLM 无缝处理,从而带来更有效和可扩展的客户服务解决方案。
选择知识库文章
在此示例中,我们将使用 OpenAI 网站上的一组公开可用的帮助中心文章,并将它们转换为 LLM 可以执行的内部例程。除了将策略转换为例程外,我们还将让模型生成允许 LLM 代表用户执行操作的函数。这对于允许 LLM 执行与人工代理相同的操作以及访问仅从策略文档中无法立即获得的其他信息是必需的。
我们将首先使用以下帮助中心文章转换为例程:
from openai import OpenAI
from IPython.display import display, HTML
import pandas as pd
from concurrent.futures import ThreadPoolExecutor
import csv
client = OpenAI()
MODEL = 'o1-preview'
我们的文章存储在可访问的 csv 文件中。我们将把这些文章并行传递给 o1-preview,并生成初始例程。
我们将例程转换的说明包括:
- 将策略从面向外部的文档转换为面向内部的、可编程执行的例程
- 将策略分解为具体的操作和子操作
- 概述在步骤之间移动的具体条件
- 确定何时需要外部知识/操作,并定义可用于获取该信息的函数
articles = []
with open('../data/helpcenter_articles.csv', mode='r', encoding='utf-8') as file:
reader = csv.DictReader(file)
for row in reader:
articles.append({
"policy": row["policy"],
"content": row["content"]
})
CONVERSION_PROMPT = """
您是一位乐于助人的助手,负责将面向外部的帮助中心文章转换为面向内部的、可编程执行的例程,并针对 LLM 进行优化。
使用此例程的 LLM 将负责阅读策略、回答客户的来电问题以及帮助将案例推向解决方案。
请遵循以下说明:
1. **仔细审查客户服务策略**,确保所有步骤都已涵盖。不跳过任何步骤或策略至关重要。
2. **将说明组织成逻辑性的、循序渐进的顺序**,使用指定的格式。
3. **使用以下格式**:
- **主操作编号**(例如,1、2、3)。
- **子操作在相关主操作下列出**(例如,1a、1b)。
**子操作应在新行开始**
- **使用清晰的“如果……那么……否则……”语句指定条件**(例如,“如果产品在 30 天内购买,则……”)。
- **对于需要客户提供更多信息的说明**,请提供礼貌且专业的提示来询问额外信息。
- **对于需要从外部系统获取数据的操作**,请编写一个使用反引号指定函数名的步骤(例如,`call the check_delivery_date function`)。
- **如果某个步骤需要客户服务代理采取行动**(例如,处理退款),请为该操作生成一个函数调用(例如,`call the process_refund function`)。
- **通过提供函数目的和所需参数的简要说明来定义任何新函数**。
- **如果助手可以代表用户执行操作**,请包含一个用于该操作的函数调用(例如,`call the change_email_address function`),并确保该函数已定义其目的和所需参数。
- 此操作可能未在帮助中心文章中明确定义,但可以执行以帮助用户更快地解决其查询。
- **案例解决之前的最后一步应始终是询问是否还有其他可以帮助您的**。
- **以调用 `case_resolution` 函数作为最后一步来结束案例解决**。
4. **确保合规性**,确保所有步骤都符合公司政策、隐私法规和法律要求。
5. **处理异常或升级**,通过指定超出标准策略的场景的步骤。
**重要提示**:如果您在任何时候不确定,请回复“我不知道”。
请将客户服务策略转换为格式化的例程,确保其易于遵循和以编程方式执行。
"""
def generate_routine(policy):
try:
messages = [
{
"role": "user",
"content": f"""
{CONVERSION_PROMPT}
POLICY:
{policy}
"""
}
]
response = client.chat.completions.create(
model=MODEL,
messages=messages
)
return response.choices[0].message.content
except Exception as e:
print(f"An error occurred: {e}")
def process_article(article):
routine = generate_routine(article['content'])
return {"policy": article['policy'], "content": article['content'], "routine": routine}
with ThreadPoolExecutor() as executor:
results = list(executor.map(process_article, articles))
我们将把例程的结果存储在一个数据框中并打印出来,以便我们初步了解。
df = pd.DataFrame(results)
# Set display options to show all text in the dataframe cells
pd.set_option('display.max_colwidth', None)
# Function to display formatted text in HTML
def display_formatted_dataframe(df):
def format_text(text):
return text.replace('\n', '<br>')
df_formatted = df.copy()
df_formatted['content'] = df_formatted['content'].apply(format_text)
df_formatted['routine'] = df_formatted['routine'].apply(format_text)
display(HTML(df_formatted.to_html(escape=False, justify='left')))
display_formatted_dataframe(df)
policy | content | routine | |
---|---|---|---|
0 | Delete Payment Method | How do I delete my payment method? Updated over a week ago We keep your payment method on file to cover any outstanding charges on your account. To stop charges to your payment method, please follow the steps below. ## ChatGPT You can cancel your ChatGPT Plus subscription to stop further charges at any time: Click on 'My Plan' in the ChatGPT sidebar. Click on 'Manage my subscription' in the pop-up window. Select 'Cancel Plan'. Please note that your cancellation will take effect the day after the next billing date, and you can continue using our services until then. To avoid being charged for your next billing period, please cancel your subscription at least 24 hours before your next billing date. ## API We'll need to keep a payment method on file to account for any outstanding usage costs. You're welcome to cancel your pay-as-you-go service, by clicking 'Cancel paid account' in your billing overview. After the current month's invoice has been issued, the current card will no longer be charged. If you'd like to continue using the service, add a new payment method in the billing overview page and select 'Set as default'. You'll then be able to delete the old payment method. |
1. 验证客户账户。 a. 礼貌地询问客户的电子邮件地址或账户 ID 以查找其账户。 b. `call the verify_customer_account(email_or_account_id)`. 2. 验证客户身份。 a. 礼貌地要求客户提供安全信息以确认其身份(例如,已存档付款方式的最后四位数字)。 b. `call the verify_customer_identity(account_id, security_information)`. c. 如果无法验证客户身份,则: - 通知客户,出于安全原因,我们无法在没有身份验证的情况下进行。 - 提供有关如何验证其身份的指导。 - 继续执行步骤 6。 3. 确定客户的账户类型。 a. `call the check_account_type(account_id)`. 4. 如果客户是 ChatGPT Plus 订阅者,则: a. 询问客户是否需要取消 ChatGPT Plus 订阅的帮助。 b. 如果客户同意,则: - `call the cancel_subscription(account_id)`. - 通知客户其订阅已取消,并且取消将在下一个账单日期之后生效。 - 提醒客户,他们可以继续使用我们的服务直到那时。 c. 否则: - 为客户提供取消订阅的以下步骤: - 点击 ChatGPT 侧边栏中的 **“我的计划”**。 - 点击弹出窗口中的 **“管理我的订阅”**。 - 选择 **“取消计划”**。 - 通知客户取消生效日期以及在此之前的持续访问。 - 建议客户在下一个账单日期前至少 24 小时取消,以避免被收取下一个账单周期的费用。 5. 否则,如果客户是 API 用户,则: a. 通知客户,我们需要保留付款方式以处理任何未结使用费。 b. 询问客户是否需要取消其按使用付费服务。 c. 如果客户同意,则: - `call the cancel_paid_account(account_id)`. - 通知客户,在当前月发票开具后,当前卡将不再收费。 d. 否则: - 为客户提供取消其按使用付费服务的以下步骤: - 转到 **账单概览** 页面。 - 点击 **“取消付费账户”**。 - 通知客户,在当前月发票开具后,当前卡将不再收费。 e. 如果客户希望继续使用该服务但更改付款方式: - 询问客户是否需要添加新付款方式并将其设置为默认付款方式的帮助。 - 如果客户同意: - 礼貌地请求新的付款方式详细信息。 - `call the add_payment_method(account_id, payment_details)`. - `call the set_default_payment_method(account_id, new_payment_method_id)`. - 通知客户旧付款方式已删除,新付款方式已设置为默认付款方式。 - 否则: - 指示客户在账单概览页面添加新付款方式。 - 要求他们为新付款方式选择 **“设置为默认”**。 - 通知他们然后可以删除旧付款方式。 6. 询问客户是否还有其他可以帮助他们的。 7. `call the case_resolution()`. --- **函数定义:** - `verify_customer_account(email_or_account_id)`:使用客户的电子邮件地址或账户 ID 验证客户账户。 **参数**:`email_or_account_id` - `verify_customer_identity(account_id, security_information)`:使用安全信息确认客户身份。 **参数**:`account_id`、`security_information` - `check_account_type(account_id)`:检索客户的账户类型(ChatGPT Plus 订阅者或 API 用户)。 **参数**:`account_id` - `cancel_subscription(account_id)`:取消客户的 ChatGPT Plus 订阅。 **参数**:`account_id` - `cancel_paid_account(account_id)`:取消客户的 API 按使用付费服务。 **参数**:`account_id` - `add_payment_method(account_id, payment_details)`:向客户账户添加新的付款方式。 **参数**:`account_id`、`payment_details` - `set_default_payment_method(account_id, payment_method_id)`:将付款方式设置为客户的默认付款方式。 **参数**:`account_id`、`payment_method_id` - `delete_payment_method(account_id, payment_method_id)`:从客户账户中删除付款方式。 **参数**:`account_id`、`payment_method_id` - `case_resolution()`:解决案例并将其标记为已完成。 |
1 | Business Associate Agreement | How can I get a Business Associate Agreement (BAA) with OpenAI? Information about HIPAA compliance for healthcare companies The Health Insurance Portability and Accountability Act (HIPAA) is a U.S. federal law that requires privacy and security protections for protected health information (PHI). Our API platform can be a great fit for any covered entity or business associate looking to process protected health information, and we’d be happy to assist you in fulfilling your HIPAA compliance. To use our API platform, you’ll first need a BAA with OpenAI. How do I get started? If you require a BAA before you can use our API, email us at baa@openai.com with details about your company and use case. Our team will respond within 1-2 business days. We review each BAA request on a case-by-case basis and may need additional information. The process is usually completed within a few business days. Can I get a BAA for ChatGPT? If you're interested in exploring a BAA for ChatGPT Enterprise, please contact sales. What happens if I’m not approved? We are able to approve most customers that request BAAs, but occasionally a use case doesn’t pass our team's evaluation. In that case, we’ll give feedback and context as to why that is and give you the opportunity to update your intended use of our API and re-apply. Are all API services covered by the BAA? No, only endpoints that are eligible for zero retention are covered by the BAA. You can see a list of those endpoints. Is an enterprise agreement requirement to sign a BAA? No, an enterprise agreement is not required to sign a BAA. |
1. 感谢客户并请求澄清: a. “感谢您的联系!您能否具体说明您需要的是用于使用我们的 API 的业务伙伴协议 (BAA),还是用于 ChatGPT Enterprise 的 BAA?” 2. 如果客户需要 API 的 BAA,则: a. 通知客户:“要获取我们的 API 的 BAA,请发送电子邮件至 baa@openai.com,并附上您公司和用例的详细信息。” b. 通知客户:“我们的团队将在 1-2 个工作日内回复。” c. 通知客户:“我们按案例对每个 BAA 请求进行审查,并可能需要额外信息。” d. 通知客户:“该过程通常在几个工作日内完成。” e. 通知客户:“请注意,只有符合零数据保留条件的端点才受 BAA 涵盖。” i. 调用 `provide_list_of_zero_retention_endpoints` 函数。 f. 通知客户:“签署 BAA 不需要企业协议。” 3. 如果客户需要 ChatGPT Enterprise 的 BAA,则: a. 通知客户:“要了解 ChatGPT Enterprise 的 BAA,请联系我们的销售团队。” i. 调用 `provide_sales_contact_information` 函数。 4. 如果客户未获批准,则: a. 通知客户:“我们能够批准大多数请求 BAA 的客户,但有时用例未通过我们团队的评估。” b. 通知客户:“在这种情况下,我们将提供反馈和背景信息,并让您有机会更新您打算如何使用我们的 API 并重新申请。” 5. 询问客户是否还有其他可以帮助您的: a. “今天还有什么我可以帮助您的吗?” 6. 调用 `case_resolution` 函数。 --- **函数定义:** - `provide_list_of_zero_retention_endpoints`: - **目的**:向客户提供受 BAA 涵盖的零数据保留合格 API 端点列表。 - **参数**:无。 - `provide_sales_contact_information`: - **目的**:向客户提供联系我们销售团队以处理 ChatGPT Enterprise 查询的联系信息。 - **参数**:无。 - `case_resolution`: - **目的**:完成案例并将其标记为已解决。 - **参数**:无。 |
2 | Set up prepaid billing | How can I set up prepaid billing? How it works Prepaid billing allows API users to pre-purchase usage. The credits you've bought will be applied to your monthly invoice. This means that any API usage you incur will first be deducted from the prepaid credits. If your usage exceeds the credits you've purchased, you'll then be billed for the additional amount. Prepaid billing helps developers know what they are committing to upfront which can provide more predictability for budgeting and spend management. Setting up prepaid billing If you're on a Monthly Billing plan, you may also choose to switch to prepaid billing and purchase credits upfront for API usage. - Go to your billing overview in your account settings - Click "Start payment plan" (you may see variations like "Buy credits") Note: If you previously had an arrears billing plan, you'll need to cancel this existing payment plan first. - Choose the initial amount of credits you want to purchase. The minimum purchase is $5. The maximum purchase will be based on your trust tier. - Confirm and purchase your initial amount of credits. - Use auto-recharge to set an automatic recharge amount, which is the amount of credits that will be added to your account when your balance falls below a set threshold. Please note that any purchased credits will expire after 1 year and they are non-refundable. After you’ve purchased credits, you should be able to start using the API. Note that there may be a couple minutes of delay while our systems update to reflect your credit balance. Purchasing additional credits Once you’ve consumed all your credits, your API requests will start returning an error letting you know you’ve hit your billing quota. If you’d like to continue your API usage, you can return to the billing portal and use the “Add to balance” button to purchase additional credits. Delayed billing Due to the complexity of our billing and processing systems, there may be delays in our ability to cut off access after you consume all of your credits. This excess usage may appear as a negative credit balance in your billing dashboard, and will be deducted from your next credit purchase. |
1. `call check_billing_plan(user_id)` - **Function:** `check_billing_plan(user_id)` - **Purpose:** Retrieves the user's current billing plan (e.g., Monthly Billing, Prepaid Billing, or Arrears Billing). - **Parameters:** - `user_id`: The unique identifier of the user. 2. 如果用户有欠款账单计划: 2a. 通知用户:“请注意,由于您有欠款账单计划,您需要先取消现有的付款计划,然后才能切换到预付费账单。您需要取消当前计划的帮助吗?” 2b. 如果用户同意,`call cancel_payment_plan(user_id)` - **Function:** `cancel_payment_plan(user_id)` - **Purpose:** Cancels the user's current arrears billing plan. - **Parameters:** - `user_id`: The unique identifier of the user. 3. 指导用户设置预付费账单: 3a. 指示用户:“请前往您账户设置中的账单概览。” 3b. 指示用户:“点击‘开始付款计划’(您可能会看到类似‘购买积分’的变体)。” 3c. 通知用户:“选择您想购买的初始积分金额。最低购买金额为 5 美元,最高购买金额将根据您的信任级别确定。” 3d. 指示用户:“确认并购买您的初始积分金额。” 3e. 建议用户:“您可以设置自动充值,以便在您的余额低于设定的阈值时自动向您的账户添加积分。” 4. 通知用户有关积分过期和退款政策: 4a. 通知用户:“请注意,购买的积分将在 1 年后过期,且不可退款。” 5. 通知用户有关激活时间: 5a. 通知用户:“购买积分后,您应该可以开始使用 API。请注意,在我们的系统更新以反映您的积分余额时,可能会有几分钟的延迟。” 6. 询问用户:“今天还有什么我可以帮助您的吗?” 7. 如果用户没有其他问题,则 `call case_resolution()` - **Function:** `case_resolution()` - **Purpose:** Marks the case as resolved and ends the interaction. |
3 | VAT Exemption request | How do I submit a VAT exemption request? Updated over a week ago If you are eligible for a tax exemption and would like to apply it to your account, please follow these steps: Depending on the state and if required: 1. Obtain a current tax exemption certificate from your state or local government and/or your fully completed non-profit sales tax exemption forms. The certificate/forms should include: Your name and address Tax exemption number Signatures and dates, etc. 2. Send us a copy of your certificate using the chat widget in the bottom-right corner. Please include your organization id, invoice number or email address associated with the account, so we can easily find you. Instructions on how to find these items are below. 3. Once we receive your certificate/form, we will review it and apply the tax exemption to your account. You will receive a confirmation email once the exemption has been applied. Please note that the tax exemption will only apply to future purchases. We cannot apply VAT exemptions retroactively. Where to find your account data In order to submit a Value Added Tax ('VAT') exemption request you will need the following from your organization Billing preferences: 1. Company name 2. Billing email 3. Primary business address 4. Business tax ID |
1. 问候客户并确认他们的请求。 1a. 说:“当然,我很乐意协助您提交增值税 (VAT) 豁免申请。” 2. 请求客户提供必要的信息。 2a. 礼貌地询问以下信息: - “请提供您的**公司名称**?” - “我可以知道与您的账户关联的**账单电子邮件**吗?” - “请提供您的**主要业务地址**?” - “请提供您的**企业税号**。” 2b. 如果客户需要查找此信息的帮助,请提供指导。 - 说:“您可以在您组织的账单偏好设置中找到此信息。” 3. 请求客户提供其当前的税务豁免证书副本。 3a. 说:“能否请您将您当前的**税务豁免证书**副本发送给我们?它应包含您的姓名和地址、税务豁免编号、签名和日期等。” 4. 指导客户如何发送证书。 4a. 说:“您可以使用**右下角的聊天小部件**将您的证书副本发送给我们。” 4b. 说:“请包含您的**组织 ID**、**发票号**或与您的账户关联的**电子邮件地址**,以便我们轻松找到您。” 5. 客户提供所需信息和证书后: 5a. 使用参数调用 `process_vat_exemption_request` 函数:company_name、billing_email、business_address、business_tax_id、tax_exemption_certificate、account_identifier。 5b. **定义 `process_vat_exemption_request` 函数**: - **目的**:根据提供的公司信息和证书审查并将增值税豁免应用于客户账户。 - **参数**: - company_name - billing_email - business_address - business_tax_id - tax_exemption_certificate - account_identifier(组织 ID/发票号/电子邮件地址) 6. 通知客户: 6a. 说:“谢谢。收到您的证书后,我们将把增值税豁免应用到您的账户。” 6b. 说:“一旦豁免申请成功,您将收到一封确认电子邮件。” 6c. 说:“请注意,增值税豁免仅适用于未来的购买。一旦申请成功,我们无法追溯应用增值税豁免。” 6d. 如果客户要求将增值税豁免应用于过去的购买: - 说:“抱歉,我们无法将增值税豁免应用于过去的购买。一旦增值税豁免成功应用于您的账户,它将仅适用于未来的购买。” 7. 询问是否还有其他可以帮助您的。 7a. 说:“今天还有什么我可以帮助您的吗?” 8. `call the case_resolution function` |
结果
在审查生成的例程后,我们可以得出几个见解:
- 示例响应:模型有效地生成了 LLM 在执行策略时可以使用的示例响应(例如,“指示用户:‘确认并购买您的初始积分金额。’”)。
- 离散步骤:模型在将问题分解为 LLM 需要执行的离散操作方面表现出色。每个指令都清晰明确,易于理解。
- 函数定义:例程的输出包括用于检索外部信息或触发操作的清晰定义的函数(例如,
review_and_apply_tax_exemption
、get_billing_plan
、update_payment_method
)。- 这对于任何成功的例程都至关重要,因为 LLM 通常需要与外部系统进行交互。利用函数调用是与这些系统交互和执行操作的有效方法。
- IFTTT 逻辑:模型有效地采用了 IFTTT(如果这样,那么那样)逻辑,这对于 LLM 来说非常理想(例如,“如果客户请求帮助,则继续执行步骤 3f。”)。
- 当原始知识库文章包含复杂的业务流程和图表时,这种类型的转换非常有价值。人类可能难以理解这种复杂性,而 LLM 甚至更难理解。IFTTT 逻辑易于理解,并且非常适合客户服务解决方案。
接下来做什么?
这些例程现在可以集成到代理系统中,以解决特定的客户问题。当客户请求设置预付费账单等任务的帮助时,我们可以使用分类器来确定适当的例程,并将其提供给 LLM 以直接与客户互动。除了向用户提供有关如何设置账单的说明外,该系统还可以代表用户执行该操作。
在将这些例程部署到生产环境之前,我们应该进行全面的评估,以测试和验证模型响应的质量。此过程可能需要调整例程以确保合规性和有效性。