💻 Code: Optimize log display: When the model does not exist, display it in the log.
Browse files
main.py
CHANGED
@@ -52,6 +52,15 @@ async def lifespan(app: FastAPI):
|
|
52 |
|
53 |
app = FastAPI(lifespan=lifespan, debug=is_debug)
|
54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
import asyncio
|
56 |
from time import time
|
57 |
from collections import defaultdict
|
@@ -501,10 +510,6 @@ def verify_admin_api_key(credentials: HTTPAuthorizationCredentials = Depends(sec
|
|
501 |
raise HTTPException(status_code=403, detail="Permission denied")
|
502 |
return token
|
503 |
|
504 |
-
@app.post("/v1/chat/completions", dependencies=[Depends(rate_limit_dependency)])
|
505 |
-
async def request_model(request: Union[RequestModel, ImageGenerationRequest]):
|
506 |
-
logger.info(f"Request received: {request}")
|
507 |
-
|
508 |
@app.post("/v1/chat/completions", dependencies=[Depends(rate_limit_dependency)])
|
509 |
async def request_model(request: Union[RequestModel, ImageGenerationRequest], token: str = Depends(verify_api_key)):
|
510 |
# logger.info(f"Request received: {request}")
|
|
|
52 |
|
53 |
app = FastAPI(lifespan=lifespan, debug=is_debug)
|
54 |
|
55 |
+
@app.exception_handler(HTTPException)
|
56 |
+
async def http_exception_handler(request: Request, exc: HTTPException):
|
57 |
+
if exc.status_code == 404:
|
58 |
+
logger.error(f"404 Error: {exc.detail}")
|
59 |
+
return JSONResponse(
|
60 |
+
status_code=exc.status_code,
|
61 |
+
content={"message": exc.detail},
|
62 |
+
)
|
63 |
+
|
64 |
import asyncio
|
65 |
from time import time
|
66 |
from collections import defaultdict
|
|
|
510 |
raise HTTPException(status_code=403, detail="Permission denied")
|
511 |
return token
|
512 |
|
|
|
|
|
|
|
|
|
513 |
@app.post("/v1/chat/completions", dependencies=[Depends(rate_limit_dependency)])
|
514 |
async def request_model(request: Union[RequestModel, ImageGenerationRequest], token: str = Depends(verify_api_key)):
|
515 |
# logger.info(f"Request received: {request}")
|