Corin1998 commited on
Commit
ca2e0b4
·
verified ·
1 Parent(s): 6b1a839

Create compliance.py

Browse files
Files changed (1) hide show
  1. app/compliance.py +47 -0
app/compliance.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+ import re
3
+ from typing import List, Tuple
4
+ from .openai_client import openai_judge
5
+
6
+ NG_PATTERNS = [
7
+ r"100%",
8
+ r"完全(に)?治(す|る)",
9
+ r"副作用(が)?ない",
10
+ r"医師(も)?推薦",
11
+ r"奇跡",
12
+ r"即日(で)?効果",
13
+ r"永久(に)?",
14
+ r"保証(します)?",
15
+ ]
16
+
17
+ def rule_based_check(text: str, extra_ng: List[str]| None = None) -> Tuple[bool, List[str]]:
18
+ bads = []
19
+ pats = list(NG_PATTERNS)
20
+ if extra_ng:
21
+ pats +=[re.escape(w) for w in extra_ng]
22
+ for p in pats:
23
+ if re.search(p, text, flags=re.IGNORECASE):
24
+ bads.append(p)
25
+ return (len(bads) == 0), bads
26
+
27
+ JUDGE_SYSTEM_PROMPT = """
28
+ あなたは日本の広告表現審査の専門家です。薬機法・景表法・健康増進法の観点から、次の広告文の合否を判定し、問題点を箇条書きで示し、安全な修正案を1つ提示してください。
29
+ 基準:
30
+ - 機能性表示/医薬的効能効果を断定する表現は禁止(例:治る、効く、100% 等)
31
+ - 比較優良・有名人/医師推奨の示唆は禁止
32
+ - 根拠のない数値誇張や永久/即効などの絶対表現は禁止
33
+ - 体験談は個人差注記を付記
34
+ 出力JSON形式:{"pass": true/false, "reasons": ["..."], "fixed": "..."}
35
+ """
36
+
37
+ def llm_check_and_fix(text: str) -> tuple[bool, List[str], str | None]:
38
+ resp = openai_judge(system=JUDGE_SYSTEM_PROMPT, user=f"広告文:
39
+ {text}")
40
+ try:
41
+ data = resp
42
+ ok = bool(data.get("pass", False))
43
+ reasons = [str(r) for r in data.get("reasons",[])]
44
+ fixed = str(data.get("fixed")) if (not ok and data.get("fixed")) else None
45
+ return ok, reasons, fixed
46
+ except Exception:
47
+ return True,[], None