Create main.py
Browse files
main.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException
|
| 2 |
+
from rag_service import rag_service
|
| 3 |
+
|
| 4 |
+
app = FastAPI(
|
| 5 |
+
title="Multi-Modal RAG API",
|
| 6 |
+
description="API for querying documents with text and images",
|
| 7 |
+
version="1.0.0"
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
@app.get("/")
|
| 11 |
+
async def root():
|
| 12 |
+
return {"message": "Multi-Modal RAG API is running"}
|
| 13 |
+
|
| 14 |
+
@app.post("/ask")
|
| 15 |
+
async def ask_question(question: str):
|
| 16 |
+
"""
|
| 17 |
+
Ask a question to the RAG system
|
| 18 |
+
"""
|
| 19 |
+
try:
|
| 20 |
+
response = rag_service.ask_question(question)
|
| 21 |
+
return {
|
| 22 |
+
"question": question,
|
| 23 |
+
"response": response,
|
| 24 |
+
"status": "success"
|
| 25 |
+
}
|
| 26 |
+
except Exception as e:
|
| 27 |
+
raise HTTPException(status_code=500, detail=f"Error processing question: {str(e)}")
|
| 28 |
+
|
| 29 |
+
@app.get("/health")
|
| 30 |
+
async def health_check():
|
| 31 |
+
"""
|
| 32 |
+
Health check endpoint
|
| 33 |
+
"""
|
| 34 |
+
try:
|
| 35 |
+
# Check if vectorstore is accessible
|
| 36 |
+
count = rag_service.vectorstore._collection.count()
|
| 37 |
+
return {
|
| 38 |
+
"status": "healthy",
|
| 39 |
+
"vectorstore_documents": count,
|
| 40 |
+
"docstore_documents": len(rag_service.store.store)
|
| 41 |
+
}
|
| 42 |
+
except Exception as e:
|
| 43 |
+
raise HTTPException(status_code=500, detail=f"Health check failed: {str(e)}")
|