Skip to main content

置信度门控路由

机器翻译译自英文(docs.typesafe.ai)本页 11 段已全部译完

文档索引

在以下地址获取完整的文档索引:https://docs.typesafe.ai/llms.txt 使用此文件可以在进一步探索之前发现所有可用页面。

置信度门控路由

将置信度用作第二轴。答案告诉你是什么;置信度告诉你是否采取行动。

TypeSafe 最强大的功能之一是 置信度。通过有意识地根据置信度来控制决策,你可以构建既可靠又安全的系统。

示例:语音银行命令

想象一下,你正在构建一个语音银行界面,允许用户通过语音与其账户互动。虽然你总是希望对解读用户意图抱有合理的置信度,但某些操作比其他操作风险更高,因此需要更高的置信度阈值。

%%{init: {"fontFamily": "Inter, sans-serif", "flowchart": {"rankSpacing": 35, "wrappingWidth": 300, "subGraphTitleMargin": {"top": 12, "bottom": 36}}}}%%
flowchart LR
    command["voice banking command"]

    subgraph req["TypeSafe evaluates<br/>the question"]
        intent["<b>Choice:</b> intent"]
    end

    command -- "one request<br/>command + intent<br/>question" --> req
    req -- "one response<br/>intent answer +<br/>confidence" --> gate{"<b>confidence high enough?</b><br/>your code"}
    gate -- "below 0.6<br/>or other intent" --> human["send to a support agent"]
    gate -- "check_balance<br/>at least 0.6" --> balance["show the balance"]
    gate -- "approve_transfer<br/>0.6 to 0.85" --> confirm["ask the user to confirm"]
    gate -- "approve_transfer<br/>above 0.85" --> approve["approve the transfer"]

步骤 1:确定用户意图

{
  "intent": {
    "type": "choice",
    "instructions": "用户请求执行什么操作?",
    "criteria": {
      "check_balance": "检查账户余额",
      "approve_transfer": "批准待处理的转账请求",
      "other": "其他"
    }
  }
}

步骤 2:置信度门控路由

action = response.answers["intent"]

# Below 0.6 confidence on any action, route to a human
if action.confidence < 0.6:
    route_to_support_agent(account_id)

elif action.choice == "check_balance":
    # Low stakes. 0.6 confidence is sufficient.
    show_balance(account_id)

elif action.choice == "approve_transfer":
    if action.confidence > 0.85:
        # High stakes, but high confidence. Safe to act automatically.
        approve_transfer(account_id)
    else:
        # High stakes, moderate confidence. Verify intent first.
        ask_user_to_confirm("Just to confirm: you would like to approve this transfer, is that correct?")

else:
    route_to_support_agent(account_id)

0.6 的底线会捕获模型真正不确定的任何内容。高于该底线时,每个操作类型都有基于错误分类后果的自身阈值。以 0.6 的置信度检查余额是可以的,因为最坏的情况只是用户不得不听取余额读出结果。但批准转账需要非常高的置信度(>0.85),否则系统应要求用户确认。

有关如何在系统中思考置信度的更多详细信息,请参阅 置信度。