feat(proxy_server.py): refactor returning rejected message, to work with error logging

log the rejected request as a failed call to langfuse/slack alerting
This commit is contained in:
Krrish Dholakia 2024-05-20 11:14:36 -07:00
parent 45fedb83c6
commit 8fb8d068fb
7 changed files with 118 additions and 100 deletions

View file

@ -146,6 +146,7 @@ class _OPTIONAL_PromptInjectionDetection(CustomLogger):
try:
assert call_type in [
"completion",
"text_completion",
"embeddings",
"image_generation",
"moderation",
@ -192,6 +193,13 @@ class _OPTIONAL_PromptInjectionDetection(CustomLogger):
return data
except HTTPException as e:
if (
e.status_code == 400
and isinstance(e.detail, dict)
and "error" in e.detail
):
if self.prompt_injection_params.reject_as_response:
return e.detail["error"]
raise e
except Exception as e:
traceback.print_exc()