# File: api.py from fastapi import FastAPI, HTTPException from pydantic import BaseModel from data_ingestion import run_ingestion_pipeline from retrieval import rag_query import logging logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') app = FastAPI() class IngestRequest(BaseModel): query: str max_results: int = 10 class QueryRequest(BaseModel): query: str @app.post("/ingest") async def ingest(request: IngestRequest): try: result = run_ingestion_pipeline(request.query, request.max_results) return {"message": result} except Exception as e: logging.error(f"Ingestion error: {str(e)}") raise HTTPException(status_code=500, detail=str(e)) @app.post("/query") async def query(request: QueryRequest): try: result = rag_query(request.query) return {"result": result} except Exception as e: logging.error(f"Query error: {str(e)}") raise HTTPException(status_code=500, detail=str(e)) if __name__ == "__main__": import uvicorn uvicorn.run(app, host="0.0.0.0", port=8000)