feat: 可配置方案引擎通用原型(Mock 检索)
需求未定稿时可先跑通追问/判定/出方案;槽位与判定树外置 YAML,后续可接 Ragflow。 Co-authored-by: haijd <haijd@163.com>
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
|
||||
def _match_condition(cond: dict[str, Any], slots: dict[str, str]) -> bool:
|
||||
ctype = cond.get("type")
|
||||
if ctype == "always":
|
||||
return True
|
||||
slot = str(cond.get("slot") or "")
|
||||
value = str(cond.get("value") or "")
|
||||
actual = (slots.get(slot) or "").strip()
|
||||
if ctype == "slot_equals":
|
||||
return actual == value
|
||||
if ctype == "slot_contains":
|
||||
return value.lower() in actual.lower()
|
||||
return False
|
||||
|
||||
|
||||
def evaluate_tree(rules: list[dict[str, Any]], slots: dict[str, str]) -> dict[str, Any]:
|
||||
for rule in rules:
|
||||
conditions = rule.get("when_all") or []
|
||||
if all(_match_condition(c, slots) for c in conditions):
|
||||
then = dict(rule.get("then") or {})
|
||||
return {
|
||||
"rule_id": rule.get("id"),
|
||||
"description": rule.get("description"),
|
||||
**then,
|
||||
}
|
||||
return {
|
||||
"rule_id": "empty",
|
||||
"product_bundle": ["待专家确认"],
|
||||
"tech_line": "待判定",
|
||||
"summary": "未匹配到规则",
|
||||
"confidence": 0.0,
|
||||
"handoff": True,
|
||||
}
|
||||
Reference in New Issue
Block a user