เครื่องมือวัดผล: นับเฉพาะรุ่น/งานที่บอทแนะนำจริง (ผู้ใช้สั่งแก้ 26 ต.ค.)
Browse filesตัวตรวจเดิมดูแค่ "มีชื่อในข้อความไหม" — "X ทนแห้งได้แค่ 116 °C จึงไม่ถึง 120" (บอทเตือนถูก)
ถูกนับเป็นแนะนำผิด (sim4 G02 ทั้งสองรอบ · graph_apps GA-F03 r1 · r2)
eval_mentions.recommended: ตรวจทีละบรรทัด
- บรรทัดที่บอกว่าตัดออก (ไม่ถึง · ไม่ผ่าน · คัดออก · พิทช์ไม่ใช่ · ไม่มีเกรดใด …) ไม่นับ
- "ไม่แนะนำให้ใช้…ในสภาวะเปียก" · "ไม่มีเกรด PP สำหรับรุ่นนี้" · "เกรด PP ไม่ผ่าน…" = หมายเหตุเกรด
ของรุ่นที่ยังแนะนำ → นับ (ตอนตรวจชื่องาน "ไม่มีเกรด…" = ใช้กับงานนั้นไม่ได้ → ไม่นับ)
- เทิร์นที่บอกว่า "ไม่มีรุ่นที่ตรง…" → ชื่อรุ่นเป็นคำอธิบาย ยกเว้นบรรทัดที่มีคำว่าแนะนำ
simulate_customers: violations นับเฉพาะที่แนะนำ · explained_not_recommended · final_violations
(คำแนะนำสุดท้าย) · summary final_violation_pct
run_answer_eval: forbid_anywhere ใช้ตัวตรวจเดียวกัน
ให้คะแนนผลเก่าใหม่ทั้งหมด (ไล่ดูทุกบรรทัดที่เปลี่ยน)
- forbid 1,084 ข้อ: เปลี่ยนเฉพาะ GA-F03 r1 · r2 (ตก → ผ่าน)
- sim4: บทที่มีผิดเงื่อนไข 42.9% → 17.9% · คำแนะนำสุดท้ายผิด 7.1% · ได้รุ่นถูก 92.9 → 100%
test_eval_mentions 18/18 (บรรทัดจริงจาก Gemini ทั้งหมด)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Stgject6PEf1Tvn6HY6Zot
- eval_mentions.py +64 -0
- run_answer_eval.py +5 -1
- simulate_customers.py +26 -8
- test_eval_mentions.py +73 -0
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
eval_mentions.py — ตัวตรวจกลางของเครื่องมือวัดผล: ชื่อรุ่น/ชื่องานในคำตอบ "ถูกแนะนำ" หรือ "ถูกตัดออก"
|
| 3 |
+
|
| 4 |
+
ใช้โดย simulate_customers.score (ผิดเงื่อนไข) และ run_answer_eval (must_not_contain แบบ forbid_anywhere)
|
| 5 |
+
ไม่ใช่โค้ดของบอท — เปลี่ยนแค่วิธีให้คะแนน ไม่เปลี่ยนคำตอบที่ลูกค้าเห็น
|
| 6 |
+
|
| 7 |
+
ปัญหาเดิม (ผู้ใช้สั่งแก้ 26 ต.ค.)
|
| 8 |
+
ตัวตรวจดูแค่ว่า "มีชื่อในข้อความไหม" แยกไม่ออกระหว่าง
|
| 9 |
+
"แนะนำ SM254 FG50% ครับ" ← ผิดจริง
|
| 10 |
+
"SM254 FG50% ทนแห้งได้แค่ 116 °C จึงไม่ถึง 120 °C" ← บอทเตือนถูกต้อง
|
| 11 |
+
sim4 G02 (ทั้งสองรอบ) · graph_apps GA-F03 (r1 · r2) ตกเพราะแบบหลัง
|
| 12 |
+
|
| 13 |
+
กฎ (ทีละบรรทัด — คำตอบของบอทเขียนเป็นรายการ แต่ละบรรทัดพูดถึงรุ่น/งานเดียว)
|
| 14 |
+
บรรทัดที่มีคำบอกว่าตัดออก (ไม่ถึง · ไม่ผ่าน · ไม่มีเกรด · ใช้ไม่ได้ …) = ตัดออก ไม่นับ
|
| 15 |
+
"ไม่แนะนำให้ใช้ในสภาวะเปียก" เป็นคุณสมบัติของเกรด ไม่ใช่การตัดออก — ลบออกก่อนตรวจ
|
| 16 |
+
ทั้งเทิร์นบอกว่า "ไม่มีรุ่นที่ตรง…" → ชื่อรุ่นในเทิร์นนั้นเป็นคำอธิบาย ยกเว้นบรรทัดที่มีคำว่าแนะนำ
|
| 17 |
+
บรรทัดข้อความส่งต่อฝ่ายขาย (โค้ดต่อท้าย) ไม่ใช่การแนะนำ
|
| 18 |
+
"""
|
| 19 |
+
from __future__ import annotations
|
| 20 |
+
|
| 21 |
+
import re
|
| 22 |
+
|
| 23 |
+
# "ไม่แนะนำให้ใช้(เกรดนี้)ในสภาวะเปียก" = คุณสมบัติของเกรด (sim2 G09 · SM254 FG50%)
|
| 24 |
+
WET_NOTE_RX = re.compile(r"ไม่แนะนำ[^\n,()]{0,30}?เปียก")
|
| 25 |
+
# "ไม่มีเกรด PP สำหรับรุ่นนี้" = หมายเหตุเกรดของรุ่นที่ยังแนะนำอยู่ (sim2 G01 HC127 C · G06 EC508 PR11)
|
| 26 |
+
# ใช้เฉพาะตอนตรวจชื่อรุ่น — ตอนตรวจชื่องาน "ไม่มีเกรด…" แปลว่ารุ่นนี้ใช้กับงานนั้นไม่ได้ (GA-F03)
|
| 27 |
+
# "ไม่มีเกรดใดของรุ่นนี้ที่รองรับ…" = ตัดทั้งรุ่น (sim4 G02#2) — ไม่ใช่หมายเหตุเกรด จึงไม่ลบ
|
| 28 |
+
# "เกรด PP ไม่ผ่านช่วงอุณหภูมิ -30 °C" = เกรดเดียวไม่ผ่าน รุ่นยังแนะนำด้วยเกรดอื่น (sim3 G04 EC508 C)
|
| 29 |
+
GRADE_NOTE_RX = re.compile(r"(?:ไม่มี(?:ระบุ)?|ไม่ได้ระบุ)เกรด\s*[A-Z][A-Z0-9]*(?:\s*[,/และ]+\s*[A-Z][A-Z0-9]*)*"
|
| 30 |
+
r"|เกรด\s*[A-Z][A-Z0-9]*(?:/[A-Z][A-Z0-9]*)?\s*(?:ไม่ผ่าน|ไม่ถึง|ไม่รองรับ)")
|
| 31 |
+
EXCLUDE_RX = re.compile(
|
| 32 |
+
r"ไม่ถึง|ไม่ผ่าน|ใช้ไม่ได้|ใช้งานไม่ได้|ไม่รองรับ|ไม่ครอบคลุม|ไม่มี(?:ระบุ)?เกรด|ไม่ได้ระบุเกรด|ไม่ได้ผลิต|ไม่ตรง|"
|
| 33 |
+
r"ตัดออก|ถูกตัด|คัดออก|ติดเงื่อนไข|ไม่สามารถ|ไม่แนะนำ|ไม่เหมาะ|ไม่ใช่ตัวเลือก|พิทช์\S{0,6}ไม่ใช่|ไม่ใช่\s*\d|"
|
| 34 |
+
r"ต้องสอบถามฝ่ายขายโดยตรง")
|
| 35 |
+
RECOMMEND_RX = re.compile(r"(?<!ไม่)แนะนำ|ตัวเลือกตรงรุ่น")
|
| 36 |
+
NONE_RX = re.compile(r"ไม่มีรุ่นที่|ไม่มีสายพาน.*ที่ตรง|ไม่พบรุ่น|ไม่มีรุ่นใด|ไม่มีรุ่นไหน")
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def _lines(text: str) -> list[str]:
|
| 40 |
+
return [l for l in (text or "").split("\n") if l.strip()]
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def line_excludes(line: str, grade_note_excludes: bool = True) -> bool:
|
| 44 |
+
"""บรรทัดนี้พูดถึงสิ่งที่ถูกตัดออก/ใช้ไม่ได้"""
|
| 45 |
+
s = WET_NOTE_RX.sub(" ", line or "")
|
| 46 |
+
if not grade_note_excludes:
|
| 47 |
+
s = GRADE_NOTE_RX.sub(" ", s)
|
| 48 |
+
return bool(EXCLUDE_RX.search(s))
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def recommended(term: str, text: str, contains=None, grade_note_excludes: bool = True) -> bool:
|
| 52 |
+
"""term ถูกเอ่ยถึงแบบแนะนำ/ยืนยันในข้อความนี้อย่างน้อยหนึ่งบรรทัด
|
| 53 |
+
contains(term, line) — วิธีหาว่าบรรทัดมี term ไหม (ค่าเริ่มต้น: substring ไม่สนตัวพิมพ์)"""
|
| 54 |
+
has = contains or (lambda t, l: t.lower() in l.lower())
|
| 55 |
+
none_turn = bool(NONE_RX.search(text or ""))
|
| 56 |
+
for line in _lines(text):
|
| 57 |
+
if not has(term, line):
|
| 58 |
+
continue
|
| 59 |
+
if line_excludes(line, grade_note_excludes):
|
| 60 |
+
continue
|
| 61 |
+
if none_turn and not RECOMMEND_RX.search(WET_NOTE_RX.sub(" ", line)):
|
| 62 |
+
continue # "ไม่มีรุ่นที่ตรง…" → ชื่อรุ่นเป็นคำอธิบาย
|
| 63 |
+
return True
|
| 64 |
+
return False
|
|
@@ -52,6 +52,8 @@ import csv
|
|
| 52 |
import importlib
|
| 53 |
import json
|
| 54 |
import re
|
|
|
|
|
|
|
| 55 |
import sys
|
| 56 |
import time
|
| 57 |
from collections import Counter, defaultdict
|
|
@@ -186,8 +188,10 @@ def check_reply(case: dict, reply: str, error: str | None) -> dict:
|
|
| 186 |
checks["answer_avoids_forbidden"] = not any(
|
| 187 |
mentions_positively(t, verdict) for t in forbidden)
|
| 188 |
# เก็บผลแบบตรวจทั้งคำตอบไว้เป็นข้อมูล ไม่ใช้ตัดสิน
|
|
|
|
|
|
|
| 189 |
info_forbidden_anywhere = not any(
|
| 190 |
-
|
| 191 |
# เคสที่คำตอบเป็นรายการ (เช่น "งานนี้ใช้รุ่นไหน") คำต้องห้ามอยู่ในย่อหน้าหลัง ๆ ไม่ใช่ย่อหน้าแรก
|
| 192 |
# เคสแบบนี้ใส่ metrics = forbid_anywhere เพื่อตัดสินจากทั้งคำตอบ (23 ต.ค. · testcases_graph_apps)
|
| 193 |
if "forbid_anywhere" in split_tokens(case.get("metrics", "")):
|
|
|
|
| 52 |
import importlib
|
| 53 |
import json
|
| 54 |
import re
|
| 55 |
+
|
| 56 |
+
import eval_mentions as EM
|
| 57 |
import sys
|
| 58 |
import time
|
| 59 |
from collections import Counter, defaultdict
|
|
|
|
| 188 |
checks["answer_avoids_forbidden"] = not any(
|
| 189 |
mentions_positively(t, verdict) for t in forbidden)
|
| 190 |
# เก็บผลแบบตรวจทั้งคำตอบไว้เป็นข้อมูล ไม่ใช้ตัดสิน
|
| 191 |
+
# 26 ต.ค. (ผู้ใช้สั่งแก้ · GA-F03): ตรวจทีละบรรทัด — บรรทัดที่บอกว่าใช้ไม่ได้/ไม่มีเกรด ไม่นับเป็นการเสนอ
|
| 192 |
+
# (เดิมตัดประโยคที่ "แต่" ทำให้ "…เครื่องบรรจุลงลัง… แต่ ไม่มีเกรด PE, PP" นับเป็นเสนอ)
|
| 193 |
info_forbidden_anywhere = not any(
|
| 194 |
+
EM.recommended(t, reply, contains=lambda tok, line: mentions_positively(tok, line)) for t in forbidden)
|
| 195 |
# เคสที่คำตอบเป็นรายการ (เช่น "งานนี้ใช้รุ่นไหน") คำต้องห้ามอยู่ในย่อหน้าหลัง ๆ ไม่ใช่ย่อหน้าแรก
|
| 196 |
# เคสแบบนี้ใส่ metrics = forbid_anywhere เพื่อตัดสินจากทั้งคำตอบ (23 ต.ค. · testcases_graph_apps)
|
| 197 |
if "forbid_anywhere" in split_tokens(case.get("metrics", "")):
|
|
@@ -13,7 +13,10 @@ simulate_customers.py — ลูกค้าจำลองด้วย LLM ค
|
|
| 13 |
ตัวชี้วัดต่อบทสนทนา
|
| 14 |
reached บอทเอ่ยรหัสรุ่นอย่างน้อยหนึ่งรุ่น
|
| 15 |
hit รุ่นที่เอ่ยอยู่ในชุดรุ่นที่ถูก (หรือ ชุดว่าง + บอทบอกว่าไม่มี)
|
| 16 |
-
violations รุ่นที่
|
|
|
|
|
|
|
|
|
|
| 17 |
offtopic บอทปฏิเสธว่านอกเรื่องกลางบท
|
| 18 |
repeats บอทพูดข้อความเดิมซ้ำติดกัน (วนถาม)
|
| 19 |
ended done (ลูกค้าพอใจ) · giveup · max_turns · error
|
|
@@ -34,6 +37,8 @@ simulate_customers.py — ลูกค้าจำลองด้วย LLM ค
|
|
| 34 |
from __future__ import annotations
|
| 35 |
|
| 36 |
import argparse
|
|
|
|
|
|
|
| 37 |
import importlib
|
| 38 |
import json
|
| 39 |
import os
|
|
@@ -107,17 +112,29 @@ def score(g: dict, transcript: list[dict], judge: Judge, ended: str) -> dict:
|
|
| 107 |
hit = any(any(x in b for x in g.get("expect_any", [])) for b in bot)
|
| 108 |
return {**out, "reached": hit, "hit": hit, "violations": [], "mentioned": []}
|
| 109 |
acc = judge.acceptable(g)
|
| 110 |
-
mentioned = []
|
| 111 |
for b in bot:
|
|
|
|
| 112 |
for c in judge.codes_in(b):
|
| 113 |
if c not in mentioned:
|
| 114 |
mentioned.append(c)
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
if acc["ok"]:
|
| 117 |
hit = any(c in acc["ok"] for c in mentioned)
|
| 118 |
else:
|
| 119 |
-
hit = any(NONE_WORDS.search(b) for b in bot) and not
|
| 120 |
return {**out, "reached": bool(mentioned), "hit": hit, "violations": violations, "mentioned": mentioned,
|
|
|
|
| 121 |
"acceptable": acc["ok"], "acceptable_source": acc["source"]}
|
| 122 |
|
| 123 |
|
|
@@ -206,9 +223,10 @@ def latency(results: list[dict]) -> dict:
|
|
| 206 |
def summarize(results: list[dict]) -> dict:
|
| 207 |
n = len(results)
|
| 208 |
c = Counter(r["ended"] for r in results)
|
| 209 |
-
pct = lambda k: round(100 * sum(bool(r
|
| 210 |
return {"conversations": n, "hit_pct": pct("hit"), "reached_pct": pct("reached"),
|
| 211 |
-
"with_violation_pct": pct("violations"), "
|
|
|
|
| 212 |
"with_repeat_pct": pct("repeats"), "ended": dict(c),
|
| 213 |
"mean_turns": round(sum(r["turns"] for r in results) / n, 1) if n else 0.0,
|
| 214 |
"latency_sec": latency(results)}
|
|
@@ -219,9 +237,9 @@ def compare(a_path: str, b_path: str) -> None:
|
|
| 219 |
A, B = (json.load(open(p, encoding="utf-8")) for p in (a_path, b_path))
|
| 220 |
sa, sb = A["summary"], B["summary"]
|
| 221 |
print(f"{'':28}{A.get('answer_interpreter', '?'):>14}{B.get('answer_interpreter', '?'):>14}")
|
| 222 |
-
for k in ("conversations", "hit_pct", "reached_pct", "with_violation_pct", "with_offtopic_pct",
|
| 223 |
"with_repeat_pct", "mean_turns"):
|
| 224 |
-
print(f"{k:28}{sa.get(k):>14}{sb.get(k):>14}")
|
| 225 |
for part in ("all_turns", "answer_turns", "other_turns"):
|
| 226 |
for st in ("mean", "median", "p90"):
|
| 227 |
va, vb = sa["latency_sec"][part].get(st), sb["latency_sec"][part].get(st)
|
|
|
|
| 13 |
ตัวชี้วัดต่อบทสนทนา
|
| 14 |
reached บอทเอ่ยรหัสรุ่นอย่างน้อยหนึ่งรุ่น
|
| 15 |
hit รุ่นที่เอ่ยอยู่ในชุดรุ่นที่ถูก (หรือ ชุดว่าง + บอทบอกว่าไม่มี)
|
| 16 |
+
violations รุ่นที่บอทแนะนำแต่ผิดเงื่อนไขแข็ง (พิทช์ / อุณหภูมิ) — นี่คือ "ตอบผิด"
|
| 17 |
+
นับเฉพาะรุ่นที่แนะนำจริง (eval_mentions.py · ผู้ใช้สั่งแก้ 26 ต.ค.) — บรรทัดที่บอกว่ารุ่นนั้น
|
| 18 |
+
ไม่ถึง/ไม่ผ่าน/ถูกตัดออก เป็นการเตือนที่ถูกต้อง ไม่นับ · รุ่นที่เอ่ยแต่ไม่นับอยู่ใน explained_not_recommended
|
| 19 |
+
final_violations เฉพาะคำแนะนำสุดท้าย (เทิร์นล่าสุดที่บอทแนะนำรุ่น) — รายการภาพรวมช่วงแรกไม่นับ
|
| 20 |
offtopic บอทปฏิเสธว่านอกเรื่องกลางบท
|
| 21 |
repeats บอทพูดข้อความเดิมซ้ำติดกัน (วนถาม)
|
| 22 |
ended done (ลูกค้าพอใจ) · giveup · max_turns · error
|
|
|
|
| 37 |
from __future__ import annotations
|
| 38 |
|
| 39 |
import argparse
|
| 40 |
+
|
| 41 |
+
import eval_mentions as EM
|
| 42 |
import importlib
|
| 43 |
import json
|
| 44 |
import os
|
|
|
|
| 112 |
hit = any(any(x in b for x in g.get("expect_any", [])) for b in bot)
|
| 113 |
return {**out, "reached": hit, "hit": hit, "violations": [], "mentioned": []}
|
| 114 |
acc = judge.acceptable(g)
|
| 115 |
+
mentioned, recommended_codes, final_rec = [], [], []
|
| 116 |
for b in bot:
|
| 117 |
+
turn_rec = []
|
| 118 |
for c in judge.codes_in(b):
|
| 119 |
if c not in mentioned:
|
| 120 |
mentioned.append(c)
|
| 121 |
+
if EM.recommended(c, b, contains=lambda t, l: t in judge.codes_in(l), grade_note_excludes=False):
|
| 122 |
+
turn_rec.append(c)
|
| 123 |
+
# 26 ต.ค. (ผู้ใช้สั่งแก้): นับผิดเงื่อนไขเฉพาะรุ่นที่บอทแนะนำจริง — "X ทนแห้งได้แค่ 116 °C จึงไม่ถึง 120"
|
| 124 |
+
# เป็นการเตือนที่ถูกต้อง ไม่ใช่การแนะนำ (eval_mentions.py · sim4 G02)
|
| 125 |
+
recommended_codes += [c for c in turn_rec if c not in recommended_codes]
|
| 126 |
+
if turn_rec:
|
| 127 |
+
final_rec = turn_rec # คำแนะนำสุดท้าย = เทิร์นล่าสุดที่บอทแนะนำรุ่น
|
| 128 |
+
violations = [c for c in recommended_codes if c not in acc["hard_ok"]]
|
| 129 |
+
# ตัวเลขสำหรับเล่ม: รายการภาพรวมก่อนลูกค้าบอกพิทช์ (sim4 G06 · G07) ไม่ใช่คำแนะนำสุดท้าย
|
| 130 |
+
final_violations = [c for c in final_rec if c not in acc["hard_ok"]]
|
| 131 |
+
explained = [c for c in mentioned if c not in acc["hard_ok"] and c not in recommended_codes]
|
| 132 |
if acc["ok"]:
|
| 133 |
hit = any(c in acc["ok"] for c in mentioned)
|
| 134 |
else:
|
| 135 |
+
hit = any(NONE_WORDS.search(b) for b in bot) and not violations
|
| 136 |
return {**out, "reached": bool(mentioned), "hit": hit, "violations": violations, "mentioned": mentioned,
|
| 137 |
+
"explained_not_recommended": explained, "final_violations": final_violations,
|
| 138 |
"acceptable": acc["ok"], "acceptable_source": acc["source"]}
|
| 139 |
|
| 140 |
|
|
|
|
| 223 |
def summarize(results: list[dict]) -> dict:
|
| 224 |
n = len(results)
|
| 225 |
c = Counter(r["ended"] for r in results)
|
| 226 |
+
pct = lambda k: round(100 * sum(bool(r.get(k)) for r in results) / n, 1) if n else 0.0 # noqa: E731
|
| 227 |
return {"conversations": n, "hit_pct": pct("hit"), "reached_pct": pct("reached"),
|
| 228 |
+
"with_violation_pct": pct("violations"), "final_violation_pct": pct("final_violations"),
|
| 229 |
+
"with_offtopic_pct": pct("offtopic"),
|
| 230 |
"with_repeat_pct": pct("repeats"), "ended": dict(c),
|
| 231 |
"mean_turns": round(sum(r["turns"] for r in results) / n, 1) if n else 0.0,
|
| 232 |
"latency_sec": latency(results)}
|
|
|
|
| 237 |
A, B = (json.load(open(p, encoding="utf-8")) for p in (a_path, b_path))
|
| 238 |
sa, sb = A["summary"], B["summary"]
|
| 239 |
print(f"{'':28}{A.get('answer_interpreter', '?'):>14}{B.get('answer_interpreter', '?'):>14}")
|
| 240 |
+
for k in ("conversations", "hit_pct", "reached_pct", "with_violation_pct", "final_violation_pct", "with_offtopic_pct",
|
| 241 |
"with_repeat_pct", "mean_turns"):
|
| 242 |
+
print(f"{k:28}{str(sa.get(k)):>14}{str(sb.get(k)):>14}")
|
| 243 |
for part in ("all_turns", "answer_turns", "other_turns"):
|
| 244 |
for st in ("mean", "median", "p90"):
|
| 245 |
va, vb = sa["latency_sec"][part].get(st), sb["latency_sec"][part].get(st)
|
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
test_eval_mentions.py — ตัวตรวจ "แนะนำจริง หรือแค่เอ่ยถึงตอนอธิบายว่าใช้ไม่ได้" (eval_mentions.py)
|
| 3 |
+
ทุกบรรทัดมาจากคำตอบจริงของ Gemini (sim2–sim4 · graph_apps r1/r2 · 26 ต.ค.)
|
| 4 |
+
|
| 5 |
+
python test_eval_mentions.py
|
| 6 |
+
"""
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
import os
|
| 10 |
+
import sys
|
| 11 |
+
|
| 12 |
+
ROOT = os.path.dirname(os.path.abspath(__file__))
|
| 13 |
+
sys.path.insert(0, ROOT)
|
| 14 |
+
|
| 15 |
+
import eval_mentions as EM # noqa: E402
|
| 16 |
+
|
| 17 |
+
passed = failed = 0
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def ok(name, cond, detail=""):
|
| 21 |
+
global passed, failed
|
| 22 |
+
if cond:
|
| 23 |
+
passed += 1
|
| 24 |
+
print(f" ✓ {name}")
|
| 25 |
+
else:
|
| 26 |
+
failed += 1
|
| 27 |
+
print(f" ✗ {name} {detail}")
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def rec(code, text, grade_note_excludes=False):
|
| 31 |
+
return EM.recommended(code, text, grade_note_excludes=grade_note_excludes)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
print("1) ต้องนับเป็นแนะนำ")
|
| 35 |
+
for code, text in [
|
| 36 |
+
("SM254 FG50%", "### รุ่นที่แนะนำ: **Modutech SM254 FG50% (วัสดุ PA6)**\nรุ่นนี้ตรงตามเงื่อนไขทุกข้อ"),
|
| 37 |
+
("SM254 FG50%", "* **SM254 FG50%** (วัสดุ **PA6**)\n * **การทนอุณหภูมิ:** รองรับอุณหภูมิสูงในสภาวะแห้งได้"),
|
| 38 |
+
("SM254 FG50%", "รุ่น **SM254 FG50% (PA6)** จึงเป็นตัวเลือกตรงรุ่นที่แคตตาล็อกระบุไว้สำหรับงานเตาอบครับ"),
|
| 39 |
+
("HC127 C", "4. **HC127 C** — เกรดวัสดุ **POM** (พิทช์ 12.7 มม.) *(หมายเหตุ: แคตตาล็อก 2026 ไม่มีเกรด PP สำหรับรุ่นนี้)*"),
|
| 40 |
+
("EC508 PR11", "* **EC508 PR11**: ผิวเจาะรู 11% (PE, PP) *(หมายเหตุ: แคตตาล็อก 2026 ไม่มีเกรด POM สำหรับรุ่นนี้ ต้องยืนยันกับฝ่ายขาย)*"),
|
| 41 |
+
("SM254 FG50%", "11. **SM254 FG50%** — วัสดุ: PA6 *(หมายเหตุ: แคตตาล็อกไม่แนะนำให้ใช้เกรดนี้ในสภาวะเปียก)*"),
|
| 42 |
+
("EC508 C", "* **EC508 C** (พิทช์ 50.8 มม.) – แคตตาล็อกระบุวัสดุ **PE, PP** สำหรับงานแปรรูปกุ้ง (เกรด PP ไม่ผ่านช่วงอุณหภูมิ -30 °C)"),
|
| 43 |
+
]:
|
| 44 |
+
ok(f"{code}: {text[:50]}…", rec(code, text))
|
| 45 |
+
|
| 46 |
+
print("\n2) เอ่ยถึงตอนอธิบายว่าใช้ไม่ได้ — ไม่นับ")
|
| 47 |
+
NONE_TURN = ("จากการตรวจสอบ **ไม่มีรุ่นที่ตรงตามเงื่อนไขครบทั้งหมด** ครับ\n"
|
| 48 |
+
"- รุ่นที่แคตตาล็อกระบุสำหรับงานเตาอบที่มีพิทช์ 25.4 มม. คือ **SM254 FG50% (เกรด PA6)** แต่เกรด PA6 "
|
| 49 |
+
"แคตตาล็อกระบุว่าไม่แนะนำให้ใช้ในสภาวะเปียก และสภาวะเปียกไม่มีข้อมูลอุณหภูมิรองรับ\n"
|
| 50 |
+
"* **MD254 GAP48%:** เป็นพิทช์ 25.7 มม. (ไม่ใช่ 25.4 มม.)")
|
| 51 |
+
for code, text in [
|
| 52 |
+
("SM254 FG50%", NONE_TURN),
|
| 53 |
+
("MD254 GAP48%", NONE_TURN),
|
| 54 |
+
("SM254 FG50%", "สำหรับรุ่น **SM254 FG50%** แต่… รองรับแห้งสูงสุด **116 °C** ครับ จึงไม่มีเกรดใดของรุ่นนี้ที่รองรับ 120 °C ครับ"),
|
| 55 |
+
("SM254 FG50%", "แม้จะเป็นสภาวะแห้งสนิท รุ่น **SM254 FG50%** ทนแห้งสูงสุด **116 °C** จึงยังไม่ครอบคลุมอุณหภูมิ 120 °C ครับ"),
|
| 56 |
+
("SM254 FG50%", "ส่วนเรื่องช่องทางติดต่อของสายพาน SM254 FG50% ต้องสอบถามฝ่ายขายโดยตรงครับ"),
|
| 57 |
+
("EC254 C", "*(หมายเหตุ: แคตตาล็อกระบุไว้ 6 รุ่น แต่รุ่น EC254 C, HC127 C และ MP80 C ถูกคัดออกเนื่องจากพิทช์ไม่ใช่ 50.8 มม. ครับ)*"),
|
| 58 |
+
("MP80 C", "*(รุ่นอื่น ๆ ที่แคตตาล็อกระบุไว้แต่พิทช์ไม่ใช่ 2 นิ้ว ได้แก่ EC254 C พิทช์ 25.4 มม. และ MP80 C พิทช์ 8 มม.)*"),
|
| 59 |
+
("HC127 C", "ต้องกา���พิทช์ 50.8 มม. มี 3 รุ่นดังนี้ครับ (รุ่นพิทช์อื่นอย่าง EC254 C, HC127 C และ MP80 C ถูกตัดออกเนื่องจากพิทช์ไม่ตรง)"),
|
| 60 |
+
]:
|
| 61 |
+
ok(f"{code}: {text[:50]}…", not rec(code, text))
|
| 62 |
+
|
| 63 |
+
print("\n3) ชื่องาน (must_not_contain · GA-F03) — \"ไม่มีเกรด…\" = รุ่นนี้ใช้กับงานนั้นไม่ได้")
|
| 64 |
+
R1 = ("* **อุตสาหกรรมบรรจุภัณฑ์:** ในโบรชัวร์มีแนะนำสำหรับการลำเลียงเข้าเครื่องติดฉลาก, เครื่องบรรจุลงลัง "
|
| 65 |
+
"แต่เนื่องจากงานเหล่านี้แนะนำเป็นเกรด PE หรือ PP ซึ่งใน**แคตตาล็อกปี 2026 ไม่มีระบุเกรด PE และ PP สำหรับรุ่นนี้**")
|
| 66 |
+
R2 = ("* *หมายเหตุ:* สำหรับงานเฉพาะทาง เช่น เครื่องติดฉลาก, เครื่องบรรจุลงลัง เล่มแนะนำเกรด (PP, PE) เอาไว้ "
|
| 67 |
+
"แต่ในแคตตาล็อกปี 2026 ของรุ่นนี้มีเฉพาะ **POM** (ไม่มีเกรด PE, PP ในตารางสเปกหลัก)")
|
| 68 |
+
ok("GA-F03 r1 ไม่นับ", not EM.recommended("เครื่องบรรจุลงลัง", R1))
|
| 69 |
+
ok("GA-F03 r2 ไม่นับ", not EM.recommended("เครื่องบรรจุลงลัง", R2))
|
| 70 |
+
ok("ชื่องานในรายการงานที่ใช้ได้ → นับ", EM.recommended("เครื่องบรรจุลงลัง", "**บรรจุภัณฑ์**\n* เครื่องบรรจุลงลัง (POM)"))
|
| 71 |
+
|
| 72 |
+
print(f"\nรวม {passed}/{passed + failed}")
|
| 73 |
+
sys.exit(1 if failed else 0)
|