Shreya Pal commited on
Commit
3b43dcd
·
1 Parent(s): aace552

Raise transparent errors instead of passing silent ones on LLM loop bypass

Browse files
Files changed (1) hide show
  1. server/app.py +3 -5
server/app.py CHANGED
@@ -18,6 +18,8 @@ def get_openai_client():
18
  global _openai_client
19
  if _openai_client is None:
20
  api_key = os.getenv("API_KEY") or os.getenv("OPENAI_API_KEY")
 
 
21
  _openai_client = OpenAI(api_key=api_key)
22
  return _openai_client
23
 
@@ -172,11 +174,7 @@ remove = clear hate speech, credible threats, targeted harassment, highly toxic
172
  }
173
 
174
  except Exception as e:
175
- return {
176
- "decision": "flag",
177
- "confidence": 0.5,
178
- "explanation": f"LLM parsing bypassed: {str(e)}"
179
- }
180
 
181
  @app.post("/moderate")
182
  def moderate(request: ModerationRequest):
 
18
  global _openai_client
19
  if _openai_client is None:
20
  api_key = os.getenv("API_KEY") or os.getenv("OPENAI_API_KEY")
21
+ if not api_key:
22
+ raise RuntimeError("No OpenAI API key found")
23
  _openai_client = OpenAI(api_key=api_key)
24
  return _openai_client
25
 
 
174
  }
175
 
176
  except Exception as e:
177
+ raise RuntimeError(f"OpenAI call failed: {e}")
 
 
 
 
178
 
179
  @app.post("/moderate")
180
  def moderate(request: ModerationRequest):