File size: 1,920 Bytes
ca2e0b4
 
 
 
 
08ba246
ca2e0b4
08ba246
 
 
 
 
 
 
 
ca2e0b4
 
08ba246
ca2e0b4
 
 
08ba246
ca2e0b4
 
 
 
 
08ba246
ca2e0b4
 
 
 
 
 
 
 
08ba246
ca2e0b4
 
08ba246
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from __future__ import annotations
import re
from typing import List, Tuple
from .openai_client import openai_judge

# 代表的なNGワード・薬機法NG表現(例)
NG_PATTERNS = [
    r"100%",
    r"完全(に)?治(す|る)",
    r"副作用(が)?ない",
    r"医師(も)?推薦",
    r"奇跡",
    r"即日(で)?効果",
    r"永久(に)?",
    r"保証(します)?",
]

def rule_based_check(text: str, extra_ng: List[str] | None = None) -> Tuple[bool, List[str]]:
    bads = []
    pats = list(NG_PATTERNS)
    if extra_ng:
        pats += [re.escape(w) for w in extra_ng]
    for p in pats:
        if re.search(p, text, flags=re.IGNORECASE):
            bads.append(p)
    return (len(bads) == 0), bads


JUDGE_SYSTEM_PROMPT = """
あなたは日本の広告表現審査の専門家です。薬機法・景表法・健康増進法の観点から、次の広告文の合否を判定し、問題点を箇条書きで示し、安全な修正案を1つ提示してください。
基準:
- 機能性表示/医薬的効能効果を断定する表現は禁止(例:治る、効く、100% 等)
- 比較優良・有名人/医師推奨の示唆は禁止
- 根拠のない数値誇張や永久/即効などの絶対表現は禁止
- 体験談は個人差注記を付記
出力JSON形式:{"pass": true/false, "reasons": ["..."], "fixed": "..."}
"""

def llm_check_and_fix(text: str) -> tuple[bool, List[str], str | None]:
    # 改行込みの f-string を正しくクォート
    resp = openai_judge(system=JUDGE_SYSTEM_PROMPT, user=f"広告文:\n{text}")
    try:
        data = resp
        ok = bool(data.get("pass", False))
        reasons = [str(r) for r in data.get("reasons", [])]
        fixed = str(data.get("fixed")) if (not ok and data.get("fixed")) else None
        return ok, reasons, fixed
    except Exception:
        # LLM失敗時は通す(要監視)
        return True, [], None