refactor: remove hardcoded routing rules and centralize AI master rules
Some checks failed
Pre-commit / run (ubuntu-latest) (push) Has been cancelled
Deploy Sphinx documentation to Pages / build_en (ubuntu-latest, 3.10) (push) Has been cancelled
Deploy Sphinx documentation to Pages / build_zh (ubuntu-latest, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (macos-15, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (macos-15, 3.11) (push) Has been cancelled
Python Unittest Coverage / test (macos-15, 3.12) (push) Has been cancelled
Python Unittest Coverage / test (ubuntu-latest, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (ubuntu-latest, 3.11) (push) Has been cancelled
Python Unittest Coverage / test (ubuntu-latest, 3.12) (push) Has been cancelled
Python Unittest Coverage / test (windows-latest, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (windows-latest, 3.11) (push) Has been cancelled
Python Unittest Coverage / test (windows-latest, 3.12) (push) Has been cancelled
Some checks failed
Pre-commit / run (ubuntu-latest) (push) Has been cancelled
Deploy Sphinx documentation to Pages / build_en (ubuntu-latest, 3.10) (push) Has been cancelled
Deploy Sphinx documentation to Pages / build_zh (ubuntu-latest, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (macos-15, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (macos-15, 3.11) (push) Has been cancelled
Python Unittest Coverage / test (macos-15, 3.12) (push) Has been cancelled
Python Unittest Coverage / test (ubuntu-latest, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (ubuntu-latest, 3.11) (push) Has been cancelled
Python Unittest Coverage / test (ubuntu-latest, 3.12) (push) Has been cancelled
Python Unittest Coverage / test (windows-latest, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (windows-latest, 3.11) (push) Has been cancelled
Python Unittest Coverage / test (windows-latest, 3.12) (push) Has been cancelled
This commit is contained in:
@@ -11,35 +11,10 @@ if str(ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(ROOT))
|
||||
|
||||
from app.orchestrator import Orchestrator
|
||||
from app.rules import detect_intent, detect_order_status, has_map_or_political_risk, requests_external_contact
|
||||
from app.state_machine import evolve_after_sales_state, migrate_state_schema
|
||||
|
||||
CASES_PATH = ROOT / "golden" / "golden_cases.jsonl"
|
||||
|
||||
|
||||
def heuristic_decide(msg: str, goods_order: str) -> tuple[str, str, dict]:
|
||||
m = (msg or "")
|
||||
intent = detect_intent(m)
|
||||
order_status = detect_order_status(goods_order or "")
|
||||
|
||||
if has_map_or_political_risk(m) or requests_external_contact(m):
|
||||
route, action = "risk", "transfer"
|
||||
elif "退款" in m:
|
||||
route, action = "after_sales", "reply"
|
||||
elif intent == "image":
|
||||
route, action = "quote", "quote"
|
||||
elif any(k in m for k in ["多少钱", "报价", "价格", "怎么收费"]):
|
||||
route, action = "quote", "reply"
|
||||
elif order_status == "paid":
|
||||
route, action = "after_sales", "reply"
|
||||
else:
|
||||
route, action = "pre_sales", "reply"
|
||||
|
||||
state = migrate_state_schema({})
|
||||
state = evolve_after_sales_state(state, route=route, action=action, intent=intent, order_status=order_status, msg=m)
|
||||
return route, action, state
|
||||
|
||||
|
||||
async def full_decide(orch: Orchestrator, cid: str, msg: str, goods_order: str) -> tuple[str, str, dict]:
|
||||
context = {
|
||||
"customer_key": f"demo_acc:{cid}",
|
||||
@@ -58,7 +33,7 @@ async def full_decide(orch: Orchestrator, cid: str, msg: str, goods_order: str)
|
||||
|
||||
async def main() -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--mode", choices=["heuristic", "full"], default="heuristic")
|
||||
parser.add_argument("--mode", choices=["full"], default="full")
|
||||
parser.add_argument("--cases", default=str(CASES_PATH))
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -69,16 +44,13 @@ async def main() -> int:
|
||||
|
||||
cases = [json.loads(line) for line in p.read_text(encoding="utf-8").splitlines() if line.strip()]
|
||||
|
||||
orch = Orchestrator() if args.mode == "full" else None
|
||||
orch = Orchestrator()
|
||||
|
||||
passed = 0
|
||||
failed = 0
|
||||
for i, c in enumerate(cases, 1):
|
||||
cid = f"case_{i}"
|
||||
if args.mode == "full":
|
||||
route, action, state = await full_decide(orch, cid, c.get("msg", ""), c.get("goods_order", ""))
|
||||
else:
|
||||
route, action, state = heuristic_decide(c.get("msg", ""), c.get("goods_order", ""))
|
||||
route, action, state = await full_decide(orch, cid, c.get("msg", ""), c.get("goods_order", ""))
|
||||
|
||||
ok = route == c.get("expected_route") and action == c.get("expected_action")
|
||||
if ok and c.get("expected_stage"):
|
||||
|
||||
Reference in New Issue
Block a user