tune: enforce shorter and more colloquial outbound replies
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 19:43:59 +08:00
parent c2d8853ae4
commit baa46156f9
3 changed files with 24 additions and 2 deletions

View File

@@ -91,6 +91,7 @@ class QingjianClient:
def _shorten_reply(self, text: str) -> str:
max_len = max(8, int(SHORT_REPLY_MAX_CHARS))
t = str(text or "").strip()
t = self._humanize_reply(t)
if len(t) <= max_len:
return t
parts = re.split(r"[。!?!?]", t)
@@ -99,6 +100,27 @@ class QingjianClient:
head = head[:max_len].rstrip(",;: ")
return head or t[:max_len]
@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
def _is_invalid_ai_reply(text: str) -> bool:
t = str(text or "").strip().lower()

View File

@@ -16,7 +16,7 @@ MESSAGE_DEBOUNCE_SECONDS = int(os.getenv("MESSAGE_DEBOUNCE_SECONDS", "6"))
AUTO_QUOTE_WAIT_SECONDS = int(os.getenv("AUTO_QUOTE_WAIT_SECONDS", "18"))
AGENT_MAX_ITERS = int(os.getenv("AGENT_MAX_ITERS", "3"))
FAST_ROUTE_ENABLED = os.getenv("FAST_ROUTE_ENABLED", "1").strip() in {"1", "true", "True", "yes", "on"}
SHORT_REPLY_MAX_CHARS = int(os.getenv("SHORT_REPLY_MAX_CHARS", "28"))
SHORT_REPLY_MAX_CHARS = int(os.getenv("SHORT_REPLY_MAX_CHARS", "20"))
STORE_BACKEND = os.getenv("STORE_BACKEND", "sqlite").strip().lower()
STORE_SQLITE_PATH = os.getenv("STORE_SQLITE_PATH", "").strip()

View File

@@ -127,7 +127,7 @@ def rules_prompt() -> str:
"10) 尺寸明显超大(如>=2m*2m): 提示需补图/重做边缘, 不要直接承诺一模一样。\n"
"11) 店铺差异化: 按 acc_id/persona 口吻回复, 保持真人聊天。\n"
"12) 最终输出只允许一个动作, 不能混合。\n"
"13) reply 必须短: 优先 1 句, 一般不超过 28 个汉字, 禁止长段解释\n"
"13) reply 必须短: 1句为主, 不超过20字, 口语化, 不要客服官话和AI腔\n"
"输出格式:\n"
'{"action":"reply|quote|transfer|noop","reply":"","transfer_msg":"","quote_mode":"flush_pending|analyze_current_or_recent|collect_only","reason":""}'
)