From 4bff7db098ec3a5a372347d03615c1ff90731e34 Mon Sep 17 00:00:00 2001 From: Macky Date: Wed, 19 Aug 2026 10:19:29 +0700 Subject: [PATCH] =?UTF-8?q?fix(persona):=20openers=20must=20ASK=20or=20say?= =?UTF-8?q?=20=E0=B8=AA=E0=B8=99=E0=B9=83=E0=B8=88=20=E2=80=94=20never=20'?= =?UTF-8?q?=E0=B8=A5=E0=B8=AD=E0=B8=87=E0=B8=94=E0=B8=B9/=E0=B8=A5?= =?UTF-8?q?=E0=B8=AD=E0=B8=87/=E0=B9=81=E0=B8=84=E0=B9=88=E0=B8=A1?= =?UTF-8?q?=E0=B8=B2=E0=B8=94=E0=B8=B9'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- backend/app/services/persona_prompts.py | 20 ++++++++++++-------- backend/scripts/fix_openers.py | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/backend/app/services/persona_prompts.py b/backend/app/services/persona_prompts.py index 53d5df4..c820d31 100644 --- a/backend/app/services/persona_prompts.py +++ b/backend/app/services/persona_prompts.py @@ -50,15 +50,19 @@ RULES: 7. difficulty 1-5. special="" unless wrong_text. 8. OPENER RULE (IMPORTANT): the `opener` is what the customer says FIRST when initiation_mode="customer". Every opener — for EVERY tier, including wrong_text and every tier-C persona — must be a natural, polite, - in-character customer greeting that starts warmly or neutrally and expresses some interest or a question. - EXAMPLES (Thai): "สวัสดีครับ สนใจสินค้าตัวนี้ ขอถามราคาหน่อยได้ไหม" / "สวัสดีค่ะ เห็นโฆษณาแฟนเพจมา เลยอยากสอบถาม" / "สวัสดีครับ ซื้อของที่นี่แล้วสั่ง-จัดส่งยังไงบ้าง" / "สนใจสินค้าในแฟนเพจครับ สอบถามรายละเอียดได้ไหม". - THAI STYLE (MANDATORY): Start with "สวัสดีครับ/ค่ะ" then go straight to the question or the word "สนใจ/สอบถาม" — - 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. + in-character customer greeting that EITHER asks a question directly OR declares interest, and nothing else. + GOOD Thai openers (ask OR show interest): "สวัสดีครับ สนใจสินค้าตัวนี้ ขอถามราคาหน่อยได้ไหม" / + "สวัสดีค่ะ เห็นโฆษณาแฟนเพจมา เลยอยากสอบถามรายละเอียดครับ" / "สวัสดีครับ ขอถามหน่อย ซื้อที่ร้านแล้วจัดส่งยังไงบ้าง" / + "สนใจสินค้าในแฟนเพจครับ สอบถามราคาได้ไหม". + THAI STYLE (MANDATORY): Start with "สวัสดีครับ/ค่ะ" then go straight to a question or the word "สนใจ/สอบถาม". + NEVER phrase the opener as "ลองดู / ลอง / มาลอง / แค่มาดู / กดดู / แวะดู" (trying/looking) — Thai customers do + NOT open by saying they will "just try or browse"; they ask a question or say they are interested instead. + Do NOT open with casual English-style interjections or filler like "เฮ้", "เอ้", "เอ่อ", "hey", "hi ya", or + singsong slang ("ไง", "นี่ๆ", "ว่าไง"). For English, a plain "Hi/Hello + question" 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. + product — e.g. do NOT write "แต่ไม่คิดจะซื้อหรอกนะ", "แค่มาดูเล่น", "ก็แค่มาเมิน", "ไม่ได้จะซื้อ". + An opener must show polite interest or ask a question; it must NOT pre-dismiss, belittle, or merely say it is + "trying/looking". 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. diff --git a/backend/scripts/fix_openers.py b/backend/scripts/fix_openers.py index 00e16e1..607181f 100644 --- a/backend/scripts/fix_openers.py +++ b/backend/scripts/fix_openers.py @@ -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)