用一份虚构 CSV 读入工单,再用一次 System One 请求建议语言、意图、紧急度和人工复核状态。结果只作分流建议,不会自动回复。
来源 · JevLog 原创 · 本站原创
2026-09-23 更新:让示例实际读取样例 CSV,并合并成一次分类请求。
背景 / 问题
Section titled “背景 / 问题”客服消息常把两件事写在一起,例如催物流又要退款。这里用一条虚构工单练习分类,原文和工单 ID 始终保留。
- 准备 Python 3.10+、
typesafe-sdk和一份虚构 CSV;在线调用前将 TYPESAFE_API_KEY 放进环境变量,不要使用真实客户信息。

工单分流示意:标签先作为建议,冲突与高紧急度交给人工。AI 概念插画。
1. 读入样例工单
Section titled “1. 读入样例工单”把样例 CSV 放在脚本旁边。代码按工单 ID 找到第 7 条,并保留原文,方便逐条核对。
2. 一次请求给出分流建议
Section titled “2. 一次请求给出分流建议”一次请求返回语言、主要意图、紧急度和是否需要人工复核。样例是虚构数据;配置 API Key 后才会调用在线服务。Noul 给出复核概率(0–1),Score 按已定义的等级返回加权分值(0–2);它们都是建议,不是正确性保证。
import csvimport osfrom typesafe_sdk import Choice, Noul, Score, TypeSafeClient
assert os.environ.get("TYPESAFE_API_KEY"), "运行在线请求前请设置 TYPESAFE_API_KEY"
with open("customer_feedback.csv", newline="", encoding="utf-8-sig") as f: ticket = next(row for row in csv.DictReader(f) if row["id"] == "7")
with TypeSafeClient() as client: result = client.system_one( state={"ticket_id": ticket["id"], "ticket_text": ticket["feedback"]}, questions={ "language": Choice( instructions="Detect the language used in this support ticket.", criteria={"zh": "Chinese", "en": "English", "mixed": "Chinese and English", "other": "Other or unclear"}, ), "intent": Choice( instructions="Choose the main support intent.", criteria={"billing": "Refund, charge, or invoice", "technical": "Login, bug, or outage", "shipping": "Delivery, tracking, or address", "other": "Other or unclear"}, ), "needs_human": Noul(instructions="Should a person review this ticket before any customer-visible action?"), "urgency": Score( instructions="Choose the urgency that best fits the ticket.", criteria=["Routine", "Soon", "Urgent"], ), }, )
suggestion = { "id": ticket["id"], "original": ticket["feedback"], "language": result.choices["language"].choice, "intent": result.choices["intent"].choice, "human_review_probability": result.nouls["needs_human"].noul, "urgency_score": result.scores["urgency"].score,}print(suggestion)3. 看原文,再决定是否转人工
Section titled “3. 看原文,再决定是否转人工”先用人工标注过的工单校准转人工门槛。结果冲突、紧急或要求复核时交给人工;回复、退款和改订单仍走现有业务流程。
练习样例:下载 customer_feedback.csv,可在本地练习;非本站实测结果。
得到可复查的分类建议。这个样例只展示结果,不会创建人工队列或回复客户。
- 给不确定、紧急或缺字段的样例写明人工下一步。
Noul 接近 1 就是分类准确率吗?
Section titled “Noul 接近 1 就是分类准确率吗?”不是。它是这次请求返回的复核概率,不是分类准确率。要用人工标注过的工单校准分流门槛,并检查误报与漏判。