需求未定稿时可先跑通追问/判定/出方案;槽位与判定树外置 YAML,后续可接 Ragflow。 Co-authored-by: haijd <haijd@163.com>
54 lines
1.4 KiB
Python
54 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
import yaml
|
|
|
|
from .settings import settings
|
|
|
|
|
|
def _load_yaml(name: str) -> dict[str, Any]:
|
|
path = settings.knowledge_dir / name
|
|
with path.open(encoding="utf-8") as f:
|
|
data = yaml.safe_load(f) or {}
|
|
if not isinstance(data, dict):
|
|
raise ValueError(f"{name} must be a mapping")
|
|
return data
|
|
|
|
|
|
class BusinessConfig:
|
|
def __init__(self) -> None:
|
|
self.reload()
|
|
|
|
def reload(self) -> None:
|
|
self.slots_doc = _load_yaml("slots.yaml")
|
|
self.tree_doc = _load_yaml("decision_tree.yaml")
|
|
self.chunks_doc = _load_yaml("sample_chunks.yaml")
|
|
|
|
@property
|
|
def slots(self) -> list[dict[str, Any]]:
|
|
return list(self.slots_doc.get("slots") or [])
|
|
|
|
@property
|
|
def handoff_phrases(self) -> list[str]:
|
|
return list(self.slots_doc.get("handoff_phrases") or [])
|
|
|
|
@property
|
|
def closing_prompt(self) -> str:
|
|
return str(self.slots_doc.get("closing_prompt") or "正在生成方案…")
|
|
|
|
@property
|
|
def rules(self) -> list[dict[str, Any]]:
|
|
return sorted(self.tree_doc.get("rules") or [], key=lambda r: r.get("order", 100))
|
|
|
|
@property
|
|
def handoff_confidence_below(self) -> float:
|
|
return float(self.tree_doc.get("handoff_confidence_below", 0.55))
|
|
|
|
@property
|
|
def chunks(self) -> list[dict[str, Any]]:
|
|
return list(self.chunks_doc.get("chunks") or [])
|
|
|
|
|
|
business_config = BusinessConfig()
|