fix(persona): forbid dismissive openers + fix script for '..' and negative tails
- persona_prompts OPENER RULE: never open with dots/ellipsis and never end
an opener by dismissing/belittling the product (but ไม่คิดจะซื้อ, แค่มาดูเล่น,
ก็แค่มาเมิน, ไม่ได้จะซื้อ...) — Thai openers stay politely interested
- fix_openers.py: strip leading dots("..") and remove trailing dismissive
clauses ('ตามไม่คิดจะซื้อหรอกนะ' etc.) so existing personas are normalized
to a natural interest opener; update docstring
This commit is contained in:
@@ -56,6 +56,9 @@ RULES:
|
||||
do NOT open with casual English-style interjections or filler like "เฮ้", "เอ้", "เอ่อ", "hey", "hi ya", or
|
||||
singsong slang ("ไง", "นี่ๆ", "ว่าไง"). A question that gets to the point directly is ideal. For English,
|
||||
a plain "Hi" or "Hello" is fine.
|
||||
NEVER open with ellipsis/dots ("..", "..."), and NEVER end the opener by dismissing or downgrading the
|
||||
product — e.g. do NOT write "แต่ไม่คิดจะซื้อหรอกนะ", "แค่มาดูเล่น", "ก็แค่มาเมิน", "ไม่ได้จะซื้อ", "แต่กะแค่ลองดู".
|
||||
An opener must show polite interest or ask a question; it must NOT pre-dismiss or belittle the product.
|
||||
NEVER make the opener a complaint, a refusal, a price grumble, a "never mind", or anything negative — the
|
||||
customer's resistance must only surface DURING the conversation, not in their very first message.
|
||||
9. Language: output all human text in the requested language.
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
"""One-time data fix (run in the EasyPanel container console):
|
||||
Rewrite existing personas' openers (opener) to natural Thai.
|
||||
|
||||
Only rewords openers that OPEN with a casual interjection/filler
|
||||
(เฮ้ / เอ้ / เอ่อ / เอ๊ะ / อืม / เออ / นี่ๆ / ว่าไง / hey / hi / hiya / yo ...).
|
||||
Only rewords openers that:
|
||||
- open with a casual interjection/filler (เฮ้ / เอ้ / เอ่อ / hey / hi / yo ...),
|
||||
- open with ellipsis/dots ("..", "..."), or
|
||||
- end with a dismissive clause Thais would not say first
|
||||
("แต่ไม่คิดจะซื้อหรอกนะ", "ไม่ได้จะซื้อ", "แค่มาดูเล่น", "ก็แค่มาเมิน"...).
|
||||
Everyone else is left untouched (safe & reversible). Prints before -> after.
|
||||
|
||||
Usage:
|
||||
cd /app/backend
|
||||
python3 /path/to/fix_openers.py # or paste as a heredoc
|
||||
python3 scripts/fix_openers.py
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -30,6 +33,15 @@ FILLER = re.compile(
|
||||
)
|
||||
BARE_POLITE = re.compile(r"^(ครับ|ค่ะ)(\s|$)")
|
||||
THAI_CHAR = re.compile(r"[\u0E00-\u0E7F]")
|
||||
# Leading punctuation/dots ("..", "...") that look unfinished/un-natural.
|
||||
LEAD_DOTS = re.compile(r"^[\.…\s]*")
|
||||
# Trailing dismissive clauses Thais would not say in an opener
|
||||
# ("แต่ไม่คิดจะซื้อหรอกนะ", "ไม่ได้จะซื้อ", "แค่มาดูเล่น", "ก็แค่มาเมิน"...).
|
||||
DISMISS_TAIL = re.compile(
|
||||
r"\s*(?:แต่(?:ก็)?(?:ไม่(?:ได้)?คิดจะซื้อ|ไม่รู้จะซื้อ|ไม่ได้จะซื้อ|ไม่ตั้งใจซื้อ)|"
|
||||
r"แค่(?:มา)?ดู(?:เล่น)?|ก็แค่(?:มา)?ดู(?:เล่น)?|ก็แค่มาเมิน|"
|
||||
r"แต่กะแค่ลองดู|ก็แค่ลองดู)(?:หรอกนะ|หรอก|นะ|ล่ะ)?$"
|
||||
)
|
||||
|
||||
|
||||
def fix_opener(existing: str) -> str | None:
|
||||
@@ -41,17 +53,23 @@ def fix_opener(existing: str) -> str | None:
|
||||
if not THAI_CHAR.search(s):
|
||||
return None
|
||||
|
||||
# 1) Strip leading casual fillers (เฮ้ / เอ้ / เอ่อ / hey / hi / ...).
|
||||
m = FILLER.match(s)
|
||||
grand_rest = s[m.end():].strip(" ,-–—:;") if m else s.strip()
|
||||
new = grand_rest
|
||||
# 0) Strip leading dots/ellipsis and any casual filler.
|
||||
new = LEAD_DOTS.sub("", s)
|
||||
m = FILLER.match(new)
|
||||
if m:
|
||||
new = new[m.end():]
|
||||
new = new.strip(" .…,:-–—;")
|
||||
|
||||
# 2) If it now (or originally) opens with a bare politeness word, prepend
|
||||
# the proper greeting: "ครับ สนใจ..." -> "สวัสดีครับ สนใจ..."
|
||||
# 1) Remove a trailing dismissive clause ("แต่ไม่คิดจะซื้อหรอกนะ" etc.),
|
||||
# so the opener stays politely interested instead of pre-dismissing.
|
||||
new = DISMISS_TAIL.sub("", new).strip(" .…,:-–—;")
|
||||
|
||||
# 2) If it now opens with a bare politeness word, prepend the greeting:
|
||||
# "ครับ สนใจ..." -> "สวัสดีครับ สนใจ..."
|
||||
bp = BARE_POLITE.match(new)
|
||||
if bp:
|
||||
polite = new[: len(bp.group(1))]
|
||||
new = new[len(polite):].strip(" ,-–—:;") or ""
|
||||
new = new[len(polite):].strip(" .…,:-–—;") or ""
|
||||
new = "สวัสดี" + polite + ((" " + new) if new else "")
|
||||
|
||||
cleaned = " ".join(new.split())
|
||||
|
||||
Reference in New Issue
Block a user