fix(persona): openers must ASK or say สนใจ — never 'ลองดู/ลอง/แค่มาดู'

- persona_prompts OPENER RULE: openers must be a direct question OR declare
  interest ('สนใจ/สอบถาม'); explicitly forbid 'ลองดู / ลอง / มาลอง / แค่มาดู /
  กดดู / แวะดู' (trying/browsing) phrasing which Thai customers don't use
- fix_openers.py: rewrite browse/try openers into a polite natural interest
  opener ('สวัสดีครับ/ค่ะ สนใจสอบถามสินค้าครับ ขอรายละเอียดได้ไหม'), leaving
  openers that already ask a question or say สนใจ untouched
This commit is contained in:
Macky
2026-08-19 10:19:29 +07:00
parent 7fcef45649
commit 4bff7db098
2 changed files with 26 additions and 8 deletions

View File

@@ -42,6 +42,12 @@ DISMISS_TAIL = re.compile(
r"แค่(?:มา)?ดู(?:เล่น)?|ก็แค่(?:มา)?ดู(?:เล่น)?|ก็แค่มาเมิน|"
r"แต่กะแค่ลองดู|ก็แค่ลองดู)(?:หรอกนะ|หรอก|นะ|ล่ะ)?$"
)
# "just trying/looking" phrasing Thai customers do NOT use as an opener.
BROWSE_TRY = re.compile(
r"ลอง(?:เข้าไปดู|กดดู|ปล่อย|ใช้|ดู)?|แค่(?:มา)?ดู|มาลอง|กดดู|แวะดู|ดูเล่น|แค่มาอ่าน"
)
QUESTION = re.compile(r"ไหม|หรือ|ยังไง|เท่าไหร่|ไหน|กี่|ตัวไหน|มีมั้ย|\?$")
INTEREST = re.compile(r"สนใจ|สอบถาม|อยาก|ขอถาม|ต้องการ|สนใจอยาก")
def fix_opener(existing: str) -> str | None:
@@ -72,6 +78,14 @@ def fix_opener(existing: str) -> str | None:
new = new[len(polite):].strip(" .…,:-–—;") or ""
new = "สวัสดี" + polite + ((" " + new) if new else "")
# 3) A "ลองดู / ลอง / แค่มาดู / กดดู" opener (just trying/browsing, no real
# question, not declaring interest) is unnatural in Thai. Rewrite it into
# a polite interest opener. (Any opener that already asks a question or
# says "สนใจ/สอบถาม" is left alone.)
if BROWSE_TRY.search(new) and not QUESTION.search(new) and not INTEREST.search(new):
polite = "ค่ะ" if "ค่ะ" in new else "ครับ"
new = f"สวัสดี{polite} สนใจสอบถามสินค้าครับ ขอรายละเอียดได้ไหม"
cleaned = " ".join(new.split())
if not cleaned or cleaned == s:
return None # nothing meaningful changed (or was empty)