Corin1998 commited on
Commit
b587dd8
·
verified ·
1 Parent(s): 79a730b

Update app/compliance.py

Browse files
Files changed (1) hide show
  1. app/compliance.py +3 -8
app/compliance.py CHANGED
@@ -3,7 +3,6 @@ import re
3
  from typing import List, Tuple
4
  from .openai_client import openai_judge
5
 
6
- # 代表的なNGワード・薬機法NG表現(例)
7
  NG_PATTERNS = [
8
  r"100%",
9
  r"完全(に)?治(す|る)",
@@ -25,7 +24,6 @@ def rule_based_check(text: str, extra_ng: List[str] | None = None) -> Tuple[bool
25
  bads.append(p)
26
  return (len(bads) == 0), bads
27
 
28
-
29
  JUDGE_SYSTEM_PROMPT = """
30
  あなたは日本の広告表現審査の専門家です。薬機法・景表法・健康増進法の観点から、次の広告文の合否を判定し、問題点を箇条書きで示し、安全な修正案を1つ提示してください。
31
  基準:
@@ -37,14 +35,11 @@ JUDGE_SYSTEM_PROMPT = """
37
  """
38
 
39
  def llm_check_and_fix(text: str) -> tuple[bool, List[str], str | None]:
40
- # 改行込みの f-string を正しくクォート
41
  resp = openai_judge(system=JUDGE_SYSTEM_PROMPT, user=f"広告文:\n{text}")
42
  try:
43
- data = resp
44
- ok = bool(data.get("pass", False))
45
- reasons = [str(r) for r in data.get("reasons", [])]
46
- fixed = str(data.get("fixed")) if (not ok and data.get("fixed")) else None
47
  return ok, reasons, fixed
48
  except Exception:
49
- # LLM失敗時は通す(要監視)
50
  return True, [], None
 
3
  from typing import List, Tuple
4
  from .openai_client import openai_judge
5
 
 
6
  NG_PATTERNS = [
7
  r"100%",
8
  r"完全(に)?治(す|る)",
 
24
  bads.append(p)
25
  return (len(bads) == 0), bads
26
 
 
27
  JUDGE_SYSTEM_PROMPT = """
28
  あなたは日本の広告表現審査の専門家です。薬機法・景表法・健康増進法の観点から、次の広告文の合否を判定し、問題点を箇条書きで示し、安全な修正案を1つ提示してください。
29
  基準:
 
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"広告文:\n{text}")
39
  try:
40
+ ok = bool(resp.get("pass", False))
41
+ reasons = [str(r) for r in resp.get("reasons", [])]
42
+ fixed = str(resp.get("fixed")) if (not ok and resp.get("fixed")) else None
 
43
  return ok, reasons, fixed
44
  except Exception:
 
45
  return True, [], None