refactor: simplify gemini flow and tighten human-like short 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-03 09:40:08 +08:00
parent 13cc01df90
commit 382581b9bc
4 changed files with 51 additions and 139 deletions

View File

@@ -113,8 +113,13 @@ class QingjianClient:
t = self._humanize_reply(t)
if len(t) <= max_len:
return t
# 优先按句号切避免把一句话硬腰斩成“AI半句”
parts = re.split(r"[。!?!?]", t)
head = next((p.strip() for p in parts if p and p.strip()), t)
head = next((p.strip() for p in parts if p and p.strip()), "")
if not head:
# 无句号时按逗号切第一短分句
sub_parts = re.split(r"[,;:]", t)
head = next((p.strip() for p in sub_parts if p and p.strip()), t)
if len(head) > max_len:
head = head[:max_len].rstrip(",;: ")
return head or t[:max_len]
@@ -122,6 +127,15 @@ class QingjianClient:
@staticmethod
def _humanize_reply(text: str) -> str:
t = str(text or "").strip()
# 去AI腔常见口癖
t = re.sub(r"^(亲亲|宝子|宝贝|您好呀|您好哦)[,]?\s*", "", t)
t = t.replace("我这边", "")
t = t.replace("请问", "")
t = t.replace("可以先帮您评估看看哦", "我先看下")
t = t.replace("服务质量有保障", "质量没问题")
t = t.replace("这个价格已经是很优惠的啦", "这价已经很低了")
t = re.sub(r"(哈~|哦~|呀~|啦~)$", "", t)
t = re.sub(r"\s+", "", t)
return t
@staticmethod

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", "20"))
SHORT_REPLY_MAX_CHARS = int(os.getenv("SHORT_REPLY_MAX_CHARS", "18"))
STORE_BACKEND = os.getenv("STORE_BACKEND", "sqlite").strip().lower()
STORE_SQLITE_PATH = os.getenv("STORE_SQLITE_PATH", "").strip()

View File

@@ -128,7 +128,9 @@ def rules_prompt() -> str:
"E. 对话质量\n"
"1) 单次只做一个动作,不混合。\n"
"2) 避免重复同一句话;若语义相同,换表达。\n"
"3) reply 必须短: 优先 1 句口语化避免AI腔。\n"
"3) reply 必须短: 只回 1 句,优先 12-18 字口语化避免AI腔。\n"
" - 禁用词风: '亲亲''我这边''请问还有其他需求吗''服务质量有保障''作为AI'\n"
" - 优先自然短句: 例如'收到,我先看图。''发图我看下。''行,我现在算价。'\n"
"4) 不要输出思考过程,不要输出 tool_use 文本给客户。\n"
"5) 若上下文不足,先澄清 1 个关键问题,不要连续追问。\n\n"
"F. 店铺人格\n"