Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,18 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
from fastapi import FastAPI, HTTPException
|
4 |
-
from pydantic import BaseModel
|
5 |
from rag_system import RAGSystem
|
6 |
|
7 |
-
|
8 |
-
class QuestionRequest(BaseModel):
|
9 |
-
question: str
|
10 |
-
|
11 |
-
# إنشاء التطبيق
|
12 |
-
app = FastAPI(
|
13 |
-
title="ECC Compliance Assistant API",
|
14 |
-
description="Ask questions based on the ECC Cybersecurity Guide using RAG",
|
15 |
-
version="1.0.0"
|
16 |
-
)
|
17 |
|
18 |
-
# تحميل النظام عند بدء التشغيل
|
19 |
rag = RAGSystem(vector_db_path="vector_db")
|
20 |
rag.load_vectorstore()
|
21 |
rag.load_llm()
|
22 |
rag.get_prompt_template()
|
23 |
|
24 |
-
# نقطة النهاية
|
25 |
@app.post("/ask")
|
26 |
-
async def ask_question(
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
1 |
+
from fastapi import FastAPI, Request
|
|
|
|
|
|
|
2 |
from rag_system import RAGSystem
|
3 |
|
4 |
+
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
|
|
6 |
rag = RAGSystem(vector_db_path="vector_db")
|
7 |
rag.load_vectorstore()
|
8 |
rag.load_llm()
|
9 |
rag.get_prompt_template()
|
10 |
|
|
|
11 |
@app.post("/ask")
|
12 |
+
async def ask_question(request: Request):
|
13 |
+
data = await request.json()
|
14 |
+
question = data.get("question")
|
15 |
+
if not question:
|
16 |
+
return {"error": "Question is required"}
|
17 |
+
answer = rag.ask_question(question)
|
18 |
+
return {"answer": answer}
|