Spaces:
Sleeping

PERDYPTO commited on
Commit
9d1a787
·
verified ·
1 Parent(s): 01ce97a

Update app/utils/validation.py

Browse files
Files changed (1) hide show
  1. app/utils/validation.py +28 -0
app/utils/validation.py CHANGED
@@ -44,6 +44,34 @@ async def validate_image(image: UploadFile | None, mode: str) -> str | None:
44
  return None
45
 
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  # ---------------------------------------------------------------------------
48
  # AI output parsing (JSON + structured text fallback)
49
  # ---------------------------------------------------------------------------
 
44
  return None
45
 
46
 
47
+ # ---------------------------------------------------------------------------
48
+ # Refusal detection
49
+ # ---------------------------------------------------------------------------
50
+
51
+ REFUSAL_MARKERS = (
52
+ "i'm not able to",
53
+ "i am not able to",
54
+ "i can't help with",
55
+ "i cannot help with",
56
+ "i'm not going to",
57
+ "i am not going to",
58
+ "i cannot assist",
59
+ "i can't assist",
60
+ "i won't be able to",
61
+ "i will not be able to",
62
+ "i don't think i can",
63
+ "i do not think i can",
64
+ "i can't engage",
65
+ "i cannot engage",
66
+ )
67
+
68
+
69
+ def is_refusal(raw: str) -> bool:
70
+ """Detect short model refusals before attempting to parse as JSON."""
71
+ lowered = raw.strip().lower()
72
+ return len(lowered) < 200 and any(marker in lowered for marker in REFUSAL_MARKERS)
73
+
74
+
75
  # ---------------------------------------------------------------------------
76
  # AI output parsing (JSON + structured text fallback)
77
  # ---------------------------------------------------------------------------