Kashish commited on
Commit ·
a82b536
1
Parent(s): f8ab2e5
fixed dependencies issues
Browse files- .gitignore +2 -2
- app.py +16 -8
- requirements.txt +5 -3
.gitignore
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
.env
|
| 2 |
-
vectorstore/
|
| 3 |
myenv/
|
| 4 |
__pycache__/
|
| 5 |
-
*.py[cod]
|
|
|
|
|
|
| 1 |
.env
|
|
|
|
| 2 |
myenv/
|
| 3 |
__pycache__/
|
| 4 |
+
*.py[cod]
|
| 5 |
+
vectorstore/
|
app.py
CHANGED
|
@@ -1,24 +1,32 @@
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
|
|
|
| 3 |
from fastapi import FastAPI, HTTPException
|
| 4 |
from pydantic import BaseModel, Field
|
| 5 |
import logging
|
| 6 |
-
|
| 7 |
from google.genai.errors import ClientError, ServerError
|
| 8 |
-
|
| 9 |
from rag.chain import aanswer
|
| 10 |
from rag.retriever import get_retriever
|
| 11 |
|
| 12 |
logger = logging.getLogger(__name__)
|
| 13 |
|
| 14 |
-
app = FastAPI(
|
| 15 |
-
title="FAQ RAG Chatbot",
|
| 16 |
-
version="1.0.0"
|
| 17 |
-
)
|
| 18 |
|
| 19 |
-
@
|
| 20 |
-
async def
|
|
|
|
|
|
|
| 21 |
get_retriever()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
class ChatRequest(BaseModel):
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
+
from contextlib import asynccontextmanager
|
| 4 |
from fastapi import FastAPI, HTTPException
|
| 5 |
from pydantic import BaseModel, Field
|
| 6 |
import logging
|
|
|
|
| 7 |
from google.genai.errors import ClientError, ServerError
|
|
|
|
| 8 |
from rag.chain import aanswer
|
| 9 |
from rag.retriever import get_retriever
|
| 10 |
|
| 11 |
logger = logging.getLogger(__name__)
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
@asynccontextmanager
|
| 15 |
+
async def lifespan(app: FastAPI):
|
| 16 |
+
"""Pre-warm the retriever at startup so the first request is fast."""
|
| 17 |
+
logger.info("Pre-warming retriever (loading embeddings + FAISS index)...")
|
| 18 |
get_retriever()
|
| 19 |
+
logger.info("Retriever ready.")
|
| 20 |
+
yield
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
app = FastAPI(
|
| 24 |
+
title="FAQ RAG Chatbot",
|
| 25 |
+
version="1.0.0",
|
| 26 |
+
description="RAG-based chatbot for samagama internship portal - CSFAQ Project",
|
| 27 |
+
openapi_url="/openapi.json",
|
| 28 |
+
lifespan=lifespan,
|
| 29 |
+
)
|
| 30 |
|
| 31 |
|
| 32 |
class ChatRequest(BaseModel):
|
requirements.txt
CHANGED
|
@@ -7,9 +7,11 @@ numpy
|
|
| 7 |
rank-bm25
|
| 8 |
sentence-transformers
|
| 9 |
google-genai
|
| 10 |
-
|
| 11 |
-
langchain-
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
faiss-cpu
|
| 14 |
python-dotenv
|
| 15 |
langchain_huggingface
|
|
|
|
| 7 |
rank-bm25
|
| 8 |
sentence-transformers
|
| 9 |
google-genai
|
| 10 |
+
|
| 11 |
+
langchain-classic
|
| 12 |
+
langchain-community>=0.4.0
|
| 13 |
+
langchain-core>=1.2.5,<2.0.0
|
| 14 |
+
|
| 15 |
faiss-cpu
|
| 16 |
python-dotenv
|
| 17 |
langchain_huggingface
|