|
|
|
|
|
from fastapi import FastAPI, HTTPException |
|
from pydantic import BaseModel |
|
from rag_system import RAGSystem |
|
|
|
|
|
class QuestionRequest(BaseModel): |
|
question: str |
|
|
|
|
|
app = FastAPI( |
|
title="ECC Compliance Assistant API", |
|
description="Ask questions based on the ECC Cybersecurity Guide using RAG", |
|
version="1.0.0" |
|
) |
|
|
|
|
|
rag = RAGSystem(vector_db_path="vector_db") |
|
rag.load_vectorstore() |
|
rag.load_llm() |
|
rag.get_prompt_template() |
|
|
|
|
|
@app.post("/ask") |
|
async def ask_question(data: QuestionRequest): |
|
try: |
|
answer = rag.ask_question(data.question) |
|
return {"question": data.question, "answer": answer} |
|
except Exception as e: |
|
raise HTTPException(status_code=500, detail=str(e)) |