Kashish commited on
Commit ·
f9ad9a3
1
Parent(s): 83604ad
serve swagger ui at root
Browse files
app.py
CHANGED
|
@@ -13,10 +13,9 @@ logger = logging.getLogger(__name__)
|
|
| 13 |
|
| 14 |
@asynccontextmanager
|
| 15 |
async def lifespan(app: FastAPI):
|
| 16 |
-
"
|
| 17 |
-
logger.info("=== FAQ RAG Chatbot starting up ===")
|
| 18 |
yield
|
| 19 |
-
logger.info("
|
| 20 |
|
| 21 |
|
| 22 |
app = FastAPI(
|
|
@@ -24,30 +23,24 @@ app = FastAPI(
|
|
| 24 |
version="1.0.0",
|
| 25 |
description="RAG-based chatbot for samagama internship portal - CSFAQ Project",
|
| 26 |
openapi_url="/openapi.json",
|
|
|
|
| 27 |
lifespan=lifespan,
|
| 28 |
)
|
| 29 |
|
| 30 |
|
| 31 |
class ChatRequest(BaseModel):
|
| 32 |
-
question: str = Field(..., min_length=1, description="User
|
| 33 |
-
|
| 34 |
|
| 35 |
class ChatResponse(BaseModel):
|
| 36 |
question: str
|
| 37 |
answer: str
|
| 38 |
sources: list[str] = Field(default_factory=list)
|
| 39 |
|
| 40 |
-
|
| 41 |
@app.get("/health")
|
| 42 |
async def health() -> dict[str, str]:
|
| 43 |
return {"status": "ok"}
|
| 44 |
|
| 45 |
|
| 46 |
-
@app.get("/", include_in_schema=False)
|
| 47 |
-
async def root() -> dict[str, str]:
|
| 48 |
-
return {"status": "ready", "message": "FAQ RAG Chatbot is running"}
|
| 49 |
-
|
| 50 |
-
|
| 51 |
@app.post("/chat", response_model=ChatResponse)
|
| 52 |
async def chat(payload: ChatRequest) -> ChatResponse:
|
| 53 |
question = payload.question.strip()
|
|
|
|
| 13 |
|
| 14 |
@asynccontextmanager
|
| 15 |
async def lifespan(app: FastAPI):
|
| 16 |
+
logger.info("FAQ RAG Chatbot starting up")
|
|
|
|
| 17 |
yield
|
| 18 |
+
logger.info("FAQ RAG Chatbot shutting down")
|
| 19 |
|
| 20 |
|
| 21 |
app = FastAPI(
|
|
|
|
| 23 |
version="1.0.0",
|
| 24 |
description="RAG-based chatbot for samagama internship portal - CSFAQ Project",
|
| 25 |
openapi_url="/openapi.json",
|
| 26 |
+
docs_url="/",
|
| 27 |
lifespan=lifespan,
|
| 28 |
)
|
| 29 |
|
| 30 |
|
| 31 |
class ChatRequest(BaseModel):
|
| 32 |
+
question: str = Field(..., min_length=1, description="User Query..")
|
|
|
|
| 33 |
|
| 34 |
class ChatResponse(BaseModel):
|
| 35 |
question: str
|
| 36 |
answer: str
|
| 37 |
sources: list[str] = Field(default_factory=list)
|
| 38 |
|
|
|
|
| 39 |
@app.get("/health")
|
| 40 |
async def health() -> dict[str, str]:
|
| 41 |
return {"status": "ok"}
|
| 42 |
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
@app.post("/chat", response_model=ChatResponse)
|
| 45 |
async def chat(payload: ChatRequest) -> ChatResponse:
|
| 46 |
question = payload.question.strip()
|