跳到正文
DEV Community· Ujjwal Dubey·· 3 天前AI 評分56

小型企業工作流如何用成本感知分類器將簡單請求路由至較小模型(Python)

Route Easy Requests to a Smaller Model: A Cost-Aware Classifier Step for Small-Business Workflows (Python)

AI 導讀

這套面向小型企業工作流的成本感知路由方法先按關鍵字、訊息長度和附件等規則分流;規則無法判斷時,再由小模型判斷難度,只把「hard」請求交給大型模型。作者建議記錄每項請求的路由,沿用相同審批流程,並每週抽查「easy」答案,以及比較調整前後各路由處理的項目數和需人工修改的答案數。

正文

Ujjwal Dubey

Not every incoming message needs your most capable model. "What time do you open?" and "Please read this contract and flag the risky clauses" should not be priced the same way.

A small routing step keeps AI automation costs down for a small business without hurting answers that matter.

The pattern

  1. Cheap rules first (keywords, length, attachments).
  2. If rules are unsure, a small model classifies difficulty.
  3. Only "hard" items go to the larger model.
  4. Log which route each item took, so you can check the split.
EASY_HINTS = ("opening hours", "address", "price list", "where are you")

def rule_route(msg):
    text = msg["text"].lower()
    if msg.get("attachments"):
        return "hard"
    if len(text) < 120 and any(h in text for h in EASY_HINTS):
        return "easy"
    return None

def route(msg, small_classify, log):
    r = rule_route(msg)
    if r is None:
        r = small_classify(msg["text"])  # returns "easy" or "hard"
    log({"id": msg["id"], "route": r})
    return r

def handle(msg, small_model, large_model, small_classify, log):
    if route(msg, small_classify, log) == "easy":
        return small_model(msg["text"])
    return large_model(msg["text"])

Guard rails

  • Anything the small model answers still passes the same approval step.
  • Sample "easy" answers weekly; if quality drops, tighten the rules.
  • Keep the router dumb and readable. Its job is triage, not cleverness.

Check the effect

Compare a week before and after: how many items each route handled, and how many easy answers needed a human edit.

We use variations of this in workflow builds for small teams.

來源:DEV Community · dev.to