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
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user