Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Handle prompt too big error #401

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Changes from all commits
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
11 changes: 10 additions & 1 deletion agents-api/agents_api/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from fastapi.middleware.cors import CORSMiddleware
from fastapi.exceptions import RequestValidationError
from agents_api.common.exceptions import BaseCommonException
from agents_api.exceptions import PromptTooBigError
from pycozo.client import QueryException
from temporalio.service import RPCError

Expand Down Expand Up @@ -96,7 +97,7 @@ def register_exceptions(app: FastAPI):
@app.exception_handler(RPCError)
async def validation_error_handler(request: Request, exc: RPCError):
return JSONResponse(
status_code=400,
status_code=status.HTTP_400_BAD_REQUEST,
content={
"error": {"message": "job not found or invalid", "code": exc.status.name}
},
Expand All @@ -111,6 +112,14 @@ async def session_not_found_error_handler(request: Request, exc: BaseCommonExcep
)


@app.exception_handler(PromptTooBigError)
async def prompt_too_big_error(request: Request, exc: PromptTooBigError):
return JSONResponse(
status_code=status.HTTP_400_BAD_REQUEST,
content={"error": {"message": str(exc)}},
)


def main(
host="127.0.0.1",
port=8000,
Expand Down
Loading