Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@
|
|
2 |
import os
|
3 |
import logging
|
4 |
from fastapi import FastAPI, HTTPException
|
|
|
5 |
from pydantic import BaseModel
|
6 |
from huggingface_hub import InferenceClient
|
7 |
from typing import Optional
|
@@ -75,11 +76,17 @@ async def chat(request: ChatRequest):
|
|
75 |
async def root():
|
76 |
return {"message": "Welcome to the LLM Chat API. Use POST /chat endpoint to get responses."}
|
77 |
|
78 |
-
#
|
79 |
@app.exception_handler(404)
|
80 |
async def not_found_handler(request, exc):
|
81 |
-
return
|
|
|
|
|
|
|
82 |
|
83 |
@app.exception_handler(405)
|
84 |
async def method_not_allowed_handler(request, exc):
|
85 |
-
return
|
|
|
|
|
|
|
|
2 |
import os
|
3 |
import logging
|
4 |
from fastapi import FastAPI, HTTPException
|
5 |
+
from fastapi.responses import JSONResponse
|
6 |
from pydantic import BaseModel
|
7 |
from huggingface_hub import InferenceClient
|
8 |
from typing import Optional
|
|
|
76 |
async def root():
|
77 |
return {"message": "Welcome to the LLM Chat API. Use POST /chat endpoint to get responses."}
|
78 |
|
79 |
+
# Fixed error handlers
|
80 |
@app.exception_handler(404)
|
81 |
async def not_found_handler(request, exc):
|
82 |
+
return JSONResponse(
|
83 |
+
status_code=404,
|
84 |
+
content={"error": "Endpoint not found. Please use POST /chat for queries."}
|
85 |
+
)
|
86 |
|
87 |
@app.exception_handler(405)
|
88 |
async def method_not_allowed_handler(request, exc):
|
89 |
+
return JSONResponse(
|
90 |
+
status_code=405,
|
91 |
+
content={"error": "Method not allowed. Please check the API documentation."}
|
92 |
+
)
|