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

This commit is contained in:
2026-03-02 20:18:51 +08:00
parent baa46156f9
commit 674519709e
6 changed files with 68 additions and 177 deletions

View File

@@ -16,7 +16,7 @@ from .config import (
from .logger import setup_logger
from .observability import activity_event, build_trace_id
from .orchestrator import Orchestrator
from .rules import detect_intent, extract_image_urls, prefilter_message
from .rules import extract_image_urls, prefilter_message
class QingjianClient:
@@ -44,13 +44,8 @@ class QingjianClient:
return str(data.get("msg", "") or "").strip()
def _debounce_seconds(self, msg: str) -> float:
intent = detect_intent(msg)
if intent == "image":
if extract_image_urls(msg):
return 2.5
if intent in {"pricing", "finish_or_quote_trigger"}:
return 2.0
if intent == "greeting":
return 1.5
return float(MESSAGE_DEBOUNCE_SECONDS)
async def send_message(self, message: dict) -> None:
@@ -103,22 +98,6 @@ class QingjianClient:
@staticmethod
def _humanize_reply(text: str) -> str:
t = str(text or "").strip()
replacements = {
"您好呀": "在的",
"您好,": "在的,",
"您好": "在的",
"很高兴为您服务": "我在呢",
"请问您有什么需求": "你要做啥图",
"请问有什么可以帮您": "你要做啥",
"可以把要做的图发我": "图发我就行",
"请您先完成订单付款": "先拍下付款哈",
"麻烦您先完成付款": "先拍下付款哈",
"我们马上为您处理": "我马上处理",
"我这边": "我这",
}
for k, v in replacements.items():
t = t.replace(k, v)
t = t.replace("~~", "~")
return t
@staticmethod
@@ -133,11 +112,9 @@ class QingjianClient:
return False
def _fallback_reply(self, action: str) -> str:
if action == "quote":
return "我先看下,马上给你报价。"
if action == "transfer":
return "我给你转人工处理"
return "收到,我先一下"
return "给你转人工处理。"
return "收到,我先处理一下。"
def _is_outbound_echo(self, data: dict, msg: str) -> bool:
"""
@@ -177,7 +154,7 @@ class QingjianClient:
"goods_name": data.get("goods_name", ""),
"goods_order": data.get("goods_order", ""),
"msg": merged_msg,
"intent": detect_intent(merged_msg),
"intent": "unknown",
"pending_images": len(self.pending_images[key]),
"auto_quote_trigger": auto_quote,
"last_reply": self.last_reply_key.get(key, ""),
@@ -238,7 +215,7 @@ class QingjianClient:
try:
await asyncio.sleep(AUTO_QUOTE_WAIT_SECONDS)
if self.pending_images.get(key):
await self._handle_decision(data, "发完了,报价吧", auto_quote=True)
await self._handle_decision(data, "", auto_quote=True)
finally:
self.auto_quote_tasks.pop(key, None)