Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions statgpt/app/application/channel_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,20 @@ async def _channel_completion(
)
state = ChainParameters.get_state(chains_response)
state[StateVarsConfig.ERROR] = None
except openai.ContentFilterFinishReasonError as e:
_log.exception(e)
choice.append_content(
"The query was blocked by the LLM provider content filter for violating safety guidelines."
)
except openai.BadRequestError as e:
_log.exception("openai.BadRequestError")
if isinstance(error := e.body, dict) and error.get("code") == "content_filter":
raise DIALException(status_code=400, **error) from None

choice.append_content("An error occurred while processing your request.")
state[StateVarsConfig.ERROR] = str(e)
except openai.ContentFilterFinishReasonError as e:
_log.exception("openai.ContentFilterFinishReasonError")
raise DIALException(
message=str(e), status_code=400, param="prompt", code="content_filter"
) from None
except Exception as e:
_log.exception(e)
_log.exception("Exception")
choice.append_content("An error occurred while processing your request.")
state[StateVarsConfig.ERROR] = str(e)

Expand Down
3 changes: 3 additions & 0 deletions statgpt/common/config/llm_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class LLMModelsEnum(StrEnum):
GPT_4_1_MINI_2025_04_14 = "gpt-4.1-mini-2025-04-14"
GPT_4_1_NANO_2025_04_14 = "gpt-4.1-nano-2025-04-14"

GPT_4_1_2025_04_14_HF = "gpt-4.1-2025-04-14-hf"
"""GPT-4.1 models with high content filters."""

# GPT-5 models
GPT_5_MINI_2025_08_07 = "gpt-5-mini-2025-08-07"
GPT_5_1_2025_11_13 = "gpt-5.1-2025-11-13"
Expand Down
1 change: 1 addition & 0 deletions statgpt/common/utils/cancel_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ async def _watcher(request: Request, handler_task: asyncio.Task, interval: float
if await request.is_disconnected():
_log.info(f"Cancelling handler task for {request.url}")
handler_task.cancel()
return
else:
_log.debug(f"Request {request.url} still connected")
await asyncio.sleep(interval)
Loading