File size: 856 Bytes
9548472 905d2fe 9548472 3b255c5 905d2fe 9548472 3b255c5 905d2fe 9548472 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# app.py
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)) |