mirror of
https://github.com/fauxpilot/fauxpilot.git
synced 2025-08-14 02:28:06 -07:00
Reformat the error to match OpenAI's
This commit is contained in:
parent
e2486698e0
commit
b7b85461af
2 changed files with 33 additions and 4 deletions
|
@ -2,12 +2,14 @@ import logging
|
|||
import os
|
||||
|
||||
import uvicorn
|
||||
from fastapi import FastAPI, Response, HTTPException
|
||||
from fastapi import FastAPI, Request, Response
|
||||
from fastapi.responses import JSONResponse
|
||||
from sse_starlette.sse import EventSourceResponse
|
||||
|
||||
from config.log_config import uvicorn_logger
|
||||
from models import OpenAIinput
|
||||
from utils.codegen import CodeGenProxy
|
||||
from utils.errors import FauxPilotException
|
||||
|
||||
logging.config.dictConfig(uvicorn_logger)
|
||||
|
||||
|
@ -25,6 +27,12 @@ app = FastAPI(
|
|||
swagger_ui_parameters={"defaultModelsExpandDepth": -1}
|
||||
)
|
||||
|
||||
@app.exception_handler(FauxPilotException)
|
||||
async def fauxpilot_handler(request: Request, exc: FauxPilotException):
|
||||
return JSONResponse(
|
||||
status_code=400,
|
||||
content=exc.json()
|
||||
)
|
||||
|
||||
@app.post("/v1/engines/codegen/completions")
|
||||
@app.post("/v1/completions")
|
||||
|
@ -33,9 +41,11 @@ async def completions(data: OpenAIinput):
|
|||
try:
|
||||
content = codegen(data=data)
|
||||
except codegen.TokensExceedsMaximum as E:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=str(E)
|
||||
raise FauxPilotException(
|
||||
message=str(E),
|
||||
type="invalid_request_error",
|
||||
param=None,
|
||||
code=None,
|
||||
)
|
||||
|
||||
if data.get("stream") is not None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue