推测性扇出
机器翻译译自英文(docs.typesafe.ai)本页 13 段已全部译完
文档索引
在以下地址获取完整的文档索引:https://docs.typesafe.ai/llms.txt 使用此文件可以在进一步探索之前发现所有可用页面。
推测性扇出
在单次调用中发送多个问题(包括推测性问题),让你的代码决定哪些是相关的。
由于 TypeSafe 支持在单个 API 调用中发送多个问题,我们建议将系统所需的所有问题放在单个请求中,然后使用代码在事后决定哪些是相关的。所有问题都是并行评估的,因此增加更多问题通常对响应时间影响很小。
示例:支持工单分类
想象一下,你正在构建一个需要分诊支持工单的支持系统。你需要将工单分类到一个类别中。如果是 Bug 报告,你还需要确定 Bug 的严重性。
你不必先询问类别,再在后续调用中询问严重程度,你可以同时询问两者。如果工单不是 Bug 报告,你只需忽略错误严重程度问题的结果。
%%{init: {"fontFamily": "Inter, sans-serif", "flowchart": {"rankSpacing": 35, "wrappingWidth": 300, "subGraphTitleMargin": {"top": 8, "bottom": 60}}}}%%
flowchart LR
t["support ticket"]
subgraph req["TypeSafe AI model<br/>evaluates each question<br/>against the ticket in parallel"]
direction TB
c["<b>Choice:</b> category"]
b["<b>Score:</b> bug severity"]
r["<b>Noul:</b> reproducible steps?"]
f["<b>Noul:</b> refund requested?"]
s["<b>Score:</b> frustration"]
%% invisible links: without an edge these share a rank and sit side by side
c ~~~ b ~~~ r ~~~ f ~~~ s
end
t -- "one request<br/>ticket + 5 questions" --> req
req -- "one response: 5 answers<br/>decisions + probabilities" --> route{"<b>filter, combine, and route</b><br/>in your code"}
route -- "bug_report" --> eng["read severity + repro steps<br/>escalate or backlog"]
route -- "billing" --> bill["refund requested<br/>send to billing"]
route -- "feature_request" --> feat["log it<br/>sent to devs"]步骤 1:推测性扇出
{
"category": {
"type": "choice",
"instructions": "确定此支持工单的广义类别",
"criteria": {
"bug_report": "用户报告了某个损坏或产生错误的问题",
"billing": "收费、发票、退款、订阅",
"feature_request": "用户请求新功能",
"account": "登录、权限、个人资料、安全"
}
},
"bug_severity": {
"type": "score",
"instructions": "报告的严重程度如何",
"criteria": [
"视觉问题;不影响功能",
"功能损坏或降级;存在替代方案",
"阻塞性问题;无替代方案"
]
},
"has_reproducible_steps": {
"type": "noul",
"instructions": "用户描述了复现问题的具体步骤"
},
"refund_requested": {
"type": "noul",
"instructions": "用户明确要求退款或抵用券"
},
"frustration": {
"type": "score",
"instructions": "用户看起来有多挫败",
"criteria": [
"平静,实事求是",
"挫败但讲礼貌",
"非常愤怒"
]
}
}Note
推测性问题: 只有当工单是 Bug 报告时,bug_severity(错误严重程度)和 has_reproducible_steps(是否有可复现步骤)才重要。refund_requested(请求退款)仅对计费相关工单重要。我们一次性包含所有问题,因为额外的问题通常对响应时间影响甚微。如果工单结果是功能请求,错误严重程度的结果将不相关,此时你的代码路径只需忽略它即可。
步骤 2:通过代码进行路由
你的代码根据分类结果决定什么内容是相关的:
triage.py
category = response.answers["category"]
bug_severity = response.answers["bug_severity"]
bug_repro = response.answers["has_reproducible_steps"]
refund = response.answers["refund_requested"]
frustration = response.answers["frustration"]
if category.choice == "bug_report":
if bug_severity.score > 1.5 and bug_repro.noul > 0.6:
escalate_to_engineering(ticket_id, severity="high")
else:
add_to_bug_backlog(ticket_id)
elif category.choice == "billing":
if refund.noul > 0.7:
route_to_billing_with_flag(ticket_id, refund_likely=True)
else:
route_to_billing(ticket_id)
elif category.choice == "feature_request":
log_feature_request(ticket_id)
# Frustration is useful regardless of category
if frustration.score > 1.5:
flag_for_priority_response(ticket_id)完整决策树所需的一切均来自一次调用。当推测性问题不相关时会被忽略;当其相关时,可节省一次往返请求。
AI 翻译查看英文原文