用推理模型实现文档转流程
我喜欢这个 OpenAI 推理模型的实现,因为它将知识文章转换为具有条件的事件序列。
o1 模型具有先进的推理能力,似乎非常适合创建将知识文章转换为流程流的例程。
它无需大量事先训练即可处理复杂、结构化的信息,因此可以将复杂的知识文章(例如包含多步骤说明、描述性决策树或图表的文章)解构为可操作的例程。
通过利用其零样本能力,o1 可以有效地解释任务并将其分解为清晰、可管理的步骤,而无需大量提示或微调。
通过利用其识别模式和关系的能力,LLM 弥合了文本信息与可操作的结构化表示之间的差距,使其成为从知识文章创建流程流等任务的理想选择。
1、文章到例程
手动将知识库文章转换为可操作的例程或流程流是一个复杂且耗时的过程,特别是对于旨在构建自动化管道的公司而言。
每个例程都必须针对不同的用户场景,并具有明确定义的操作。
O1 已展示出以零样本效率解构文章并将其转换为例程的能力,这意味着 LLM 可以解释和遵循指令,而无需大量示例或事先针对特定任务的训练。
这大大减少了提示所需的工作量,因为例程本身的结构为 LLM 执行每个步骤提供了必要的指导。
通过将任务分解为不同的操作并在适当的情况下合并函数调用,O1 的方法使 LLM 能够无缝处理复杂的工作流程。
这种方法可以产生更有效、更可扩展的解决方案,尤其是用于增强客户服务运营。
2、符号推理
LLM 的符号推理能力使它们能够解释非结构化文本并将其转换为结构化的逻辑流程。
这些模型可以将复杂的指令或描述分解为分步过程,从而无缝转换为工作流程、决策树或流程图。
内部知识库文章通常很复杂,并且专为人类解释而设计,将这些文档转换为例程可以简化和结构化每条指令,指导 LLM 完成一系列小型、可管理的任务。
这种细粒度方法最大限度地减少了歧义,使 LLM 能够系统地处理信息,同时降低出现幻觉或偏离预期工作流程的可能性。
通过分解复杂性,例程有助于确保 LLM 在处理这些文档时具有更准确、更可靠的性能。
3、数据源
实际演示的数据源如下所示,其中包含一些来自 OpenAI 的策略。信息采用 CSV 格式。
4、工作笔记本
下面是工作 Python 代码,你可以将其按原样复制到笔记本中,代码将提示你输入 OpenAI API 密钥。可以在下面看到定义了 o1-preview
模型。
笔记本还定义了提示,之后从 GitHub 存储库获取 CSV 文件。
从这里我们定义例程生成函数,结果可以以多种方式显示。
# Install required libraries
!pip install openai==0.28 pandas requests
# Import necessary libraries
import openai
import pandas as pd
import requests
import io
# Prompt the user for the OpenAI API key
api_key = input("Please enter your OpenAI API key: ").strip()
openai.api_key = api_key
# Define the model and prompt
MODEL = 'o1-preview'
CONVERSION_PROMPT = """
You are a helpful assistant tasked with converting an external-facing help center article into an internal-facing, programmatically executable routine optimized for an LLM. Please follow these instructions:
1. **Review the customer service policy carefully** to ensure every step is accounted for.
2. **Organize the instructions into a logical, step-by-step order**, using the specified format.
3. **Use the following format**:
- **Main actions are numbered** (e.g., 1, 2, 3).
- **Sub-actions are lettered** under their relevant main actions (e.g., 1a, 1b).
- **Specify conditions using clear 'if...then...else' statements**.
- **For instructions requiring more information from the customer**, provide polite and professional prompts.
- **For actions requiring data from external systems**, write a step to call a function using backticks for the function name (e.g., `call the check_delivery_date function`).
- **Define any new functions** by providing a brief description of their purpose and required parameters.
- **The step prior to case resolution should always be to ask if there is anything more you can assist with**.
- **End with a final action for case resolution**: calling the `case_resolution` function should always be the final step.
4. **Ensure compliance** by making sure all steps adhere to company policies, privacy regulations, and legal requirements.
5. **Handle exceptions or escalations** by specifying steps for scenarios that fall outside the standard policy.
Please convert the customer service policy into the formatted routine, ensuring it is easy to follow and execute programmatically.
"""
# Fetch the CSV file from the GitHub repository
url = "https://raw.githubusercontent.com/openai/openai-cookbook/main/examples/data/helpcenter_articles.csv"
response = requests.get(url)
if response.status_code == 200:
csv_data = io.StringIO(response.text)
articles = pd.read_csv(csv_data)
print("CSV file loaded successfully.")
else:
raise Exception("Failed to fetch the CSV file. Please check the URL.")
# Define the routine generation function
def generate_routine(policy_content):
try:
response = openai.ChatCompletion.create(
model=MODEL,
messages=[
{"role": "user", "content": f"{CONVERSION_PROMPT}\n\nPOLICY:\n{policy_content}"}
]
)
return response.choices[0].message['content']
except Exception as e:
print(f"An error occurred: {e}")
return None
# Process articles and generate routines
def process_article(article):
routine = generate_routine(article['content'])
return {"policy": article['policy'], "routine": routine}
# Convert articles to a dictionary format for processing
articles_dict = articles.to_dict(orient="records")
# Generate routines
results = [process_article(article) for article in articles_dict]
# Store and display the results
df = pd.DataFrame(results)
display(df)
数据框可用于绘制信息图表……
下面的例程显示在电子表格中,请注意条件设置,采用 If-Else 方法。
5、结束语
可以将此类例程集成到代理系统中,以处理特定的客户问题。
例如,如果客户需要帮助设置预付费账单,分类器可以识别正确的例程并将其提供给 LLM 以协助客户。
系统可以指导用户完成设置或为他们完成任务。
原文链接:Transforming Documentation Into Actionable Flows with OpenAI Reasoning Models
汇智网翻译整理,转载请标明出处