Skip to content

Commit

Permalink
Add exception handling (422) for toxic content
Browse files Browse the repository at this point in the history
  • Loading branch information
Niels Ringler committed Oct 2, 2024
1 parent 47c2482 commit 0410fb4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import uvicorn
from fastapi.responses import StreamingResponse, RedirectResponse, JSONResponse
from starlette.exceptions import HTTPException

from newspaper.article import ArticleException
from openai import OpenAI, AsyncOpenAI

Expand Down Expand Up @@ -77,9 +79,8 @@ async def completion(
language = json.loads(resp[0].choices[0].message.content)['language']
content_status = json.loads(resp[1].choices[0].message.content)['content_status']
if not content_status == "valid":
response = StreamingResponse(content='')
response.content_status = content_status
return response
raise HTTPException(status_code=422, detail="Invalid content")


system_prompt = system_prompt_malicious

Expand All @@ -95,7 +96,6 @@ async def completion(
all_json= not raw_output),
media_type="text/event-stream",
)
response.content_status = content_status
return response

@app.post("/check", response_model=CheckResponse)
Expand Down

0 comments on commit 0410fb4

Please sign in to comment.