Dus Tran commited on
Commit
cf573aa
·
1 Parent(s): 1c576ea

“…I”

Browse files
Files changed (6) hide show
  1. Dockerfile +0 -21
  2. README.md +6 -6
  3. api.py +0 -3
  4. app/api/routes.py +0 -7
  5. app/core/config.py +0 -8
  6. run.sh +1 -3
Dockerfile CHANGED
@@ -1,33 +1,12 @@
1
- # Sử dụng base image Python tối ưu (nhẹ gọn)
2
  FROM python:3.12-slim
3
-
4
- # Ngăn chặn Python sinh ra file .pyc
5
  ENV PYTHONDONTWRITEBYTECODE 1
6
- # Ghi log trực tiếp lên console không qua buffer
7
  ENV PYTHONUNBUFFERED 1
8
-
9
- # Tạo thư mục làm việc trong container
10
- WORKDIR /app
11
-
12
- # Cài đặt các thư viện hệ thống cần thiết (nếu cần thiết cho compiler của một số package)
13
  RUN apt-get update && apt-get install -y --no-install-recommends \
14
  build-essential \
15
  && rm -rf /var/lib/apt/lists/*
16
-
17
- # Copy requirements trước để tận dụng Docker Cache
18
  COPY requirements.txt .
19
-
20
- # Cài đặt thư viện Python
21
  RUN pip install --no-cache-dir -r requirements.txt
22
-
23
- # Copy toàn bộ source code vào container
24
  COPY . .
25
-
26
- # Tạo sẵn thư mục data và VectorDB để tránh lỗi quyền ghi (Permissions)
27
  RUN mkdir -p /app/data /app/VectorDB
28
-
29
- # Expose cổng 8000 (cổng FastAPI chạy)
30
  EXPOSE 8000
31
-
32
- # Lệnh khởi chạy server khi container start
33
  CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8000"]
 
 
1
  FROM python:3.12-slim
 
 
2
  ENV PYTHONDONTWRITEBYTECODE 1
 
3
  ENV PYTHONUNBUFFERED 1
 
 
 
 
 
4
  RUN apt-get update && apt-get install -y --no-install-recommends \
5
  build-essential \
6
  && rm -rf /var/lib/apt/lists/*
 
 
7
  COPY requirements.txt .
 
 
8
  RUN pip install --no-cache-dir -r requirements.txt
 
 
9
  COPY . .
 
 
10
  RUN mkdir -p /app/data /app/VectorDB
 
 
11
  EXPOSE 8000
 
 
12
  CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8000"]
README.md CHANGED
@@ -1,8 +1,8 @@
1
- # 🚀 Advanced Enterprise RAG Chatbot
2
 
3
  Hệ thống Chatbot RAG (Retrieval-Augmented Generation) thông minh, được thiết kế để xử lý đa luồng câu hỏi, hỗ trợ giao diện Web trực quan và tích hợp sâu với các mô hình ngôn ngữ tiên tiến của Google và HuggingFace.
4
 
5
- ## 📊 Sơ đồ Kiến trúc Hệ thống
6
 
7
  Dưới đây là sơ đồ luồng hoạt động (Workflow) của hệ thống, bao gồm quá trình Nạp dữ liệu (Offline Ingestion) và quá trình Truy vấn thời gian thực (Online Querying):
8
 
@@ -19,7 +19,7 @@ flowchart TD
19
  D1 -- Save to Qdrant --> VDB[(Vector DB)]
20
 
21
  %% Query Pipeline
22
- U1((Student)) --> Q1([Query])
23
 
24
  Q1 --> QT[Query Transform]
25
  QT --> QR[Query Router]
@@ -45,7 +45,7 @@ flowchart TD
45
  LLM --> ANS
46
  ```
47
 
48
- ## 🛠 Frameworks & Toolkits Sử dụng
49
 
50
  Dự án này được xây dựng trên một stack công nghệ hiện đại và chuyên nghiệp:
51
 
@@ -72,7 +72,7 @@ Dự án này được xây dựng trên một stack công nghệ hiện đại
72
 
73
  ---
74
 
75
- ## ⚙️ Cài đặt & Sử dụng (Môi trường Local)
76
 
77
  ### 1. Chuẩn bị
78
  Yêu cầu: `Python 3.10+`.
@@ -106,7 +106,7 @@ python api.py
106
 
107
  ---
108
 
109
- ## 🐳 Triển khai bằng Docker (Production)
110
 
111
  Để chạy dự án một cách chuyên nghiệp và độc lập, hãy sử dụng Docker.
112
 
 
1
+ # Advanced Enterprise RAG Chatbot
2
 
3
  Hệ thống Chatbot RAG (Retrieval-Augmented Generation) thông minh, được thiết kế để xử lý đa luồng câu hỏi, hỗ trợ giao diện Web trực quan và tích hợp sâu với các mô hình ngôn ngữ tiên tiến của Google và HuggingFace.
4
 
5
+ ## Sơ đồ Kiến trúc Hệ thống
6
 
7
  Dưới đây là sơ đồ luồng hoạt động (Workflow) của hệ thống, bao gồm quá trình Nạp dữ liệu (Offline Ingestion) và quá trình Truy vấn thời gian thực (Online Querying):
8
 
 
19
  D1 -- Save to Qdrant --> VDB[(Vector DB)]
20
 
21
  %% Query Pipeline
22
+ U1((Client)) --> Q1([Query])
23
 
24
  Q1 --> QT[Query Transform]
25
  QT --> QR[Query Router]
 
45
  LLM --> ANS
46
  ```
47
 
48
+ ## Frameworks sử dụng
49
 
50
  Dự án này được xây dựng trên một stack công nghệ hiện đại và chuyên nghiệp:
51
 
 
72
 
73
  ---
74
 
75
+ ## Cài đặt & Sử dụng (Môi trường Local)
76
 
77
  ### 1. Chuẩn bị
78
  Yêu cầu: `Python 3.10+`.
 
106
 
107
  ---
108
 
109
+ ## Triển khai bằng Docker (Production)
110
 
111
  Để chạy dự án một cách chuyên nghiệp và độc lập, hãy sử dụng Docker.
112
 
api.py CHANGED
@@ -12,7 +12,6 @@ app = FastAPI(
12
  version="1.0.0"
13
  )
14
 
15
- # Cấu hình CORS để cho phép frontend gọi API
16
  app.add_middleware(
17
  CORSMiddleware,
18
  allow_origins=["*"],
@@ -21,10 +20,8 @@ app.add_middleware(
21
  allow_headers=["*"],
22
  )
23
 
24
- # Gắn các route đã định nghĩa vào app chính
25
  app.include_router(router, prefix="/api/v1")
26
 
27
- # Phục vụ các file tĩnh (Frontend UI)
28
  app.mount("/static", StaticFiles(directory="static"), name="static")
29
 
30
  @app.get("/", summary="Giao diện Web Chatbot")
 
12
  version="1.0.0"
13
  )
14
 
 
15
  app.add_middleware(
16
  CORSMiddleware,
17
  allow_origins=["*"],
 
20
  allow_headers=["*"],
21
  )
22
 
 
23
  app.include_router(router, prefix="/api/v1")
24
 
 
25
  app.mount("/static", StaticFiles(directory="static"), name="static")
26
 
27
  @app.get("/", summary="Giao diện Web Chatbot")
app/api/routes.py CHANGED
@@ -6,11 +6,7 @@ router = APIRouter()
6
 
7
  @router.post("/chat", response_model=ChatResponse, summary="Gửi câu hỏi cho RAG Chatbot")
8
  async def chat_endpoint(request: ChatRequest):
9
- """
10
- Endpoint nhận câu hỏi từ người dùng và trả về câu trả lời sử dụng hệ thống RAG Agent.
11
- """
12
  try:
13
- # Gọi RAG agent đã có
14
  response_text = run_advanced_rag_agent(request.query, request.session_id)
15
  return ChatResponse(response=response_text, session_id=request.session_id)
16
  except Exception as e:
@@ -20,7 +16,4 @@ async def chat_endpoint(request: ChatRequest):
20
 
21
  @router.get("/health", summary="Kiểm tra trạng thái API")
22
  async def health_check():
23
- """
24
- Endpoint đơn giản để kiểm tra xem API có đang hoạt động không.
25
- """
26
  return {"status": "ok", "message": "API is running"}
 
6
 
7
  @router.post("/chat", response_model=ChatResponse, summary="Gửi câu hỏi cho RAG Chatbot")
8
  async def chat_endpoint(request: ChatRequest):
 
 
 
9
  try:
 
10
  response_text = run_advanced_rag_agent(request.query, request.session_id)
11
  return ChatResponse(response=response_text, session_id=request.session_id)
12
  except Exception as e:
 
16
 
17
  @router.get("/health", summary="Kiểm tra trạng thái API")
18
  async def health_check():
 
 
 
19
  return {"status": "ok", "message": "API is running"}
app/core/config.py CHANGED
@@ -3,21 +3,15 @@ from dotenv import load_dotenv
3
  from langchain_google_genai import ChatGoogleGenerativeAI
4
  from langchain_huggingface import HuggingFaceEmbeddings
5
 
6
- # Load environment variables from .env file
7
  load_dotenv()
8
 
9
- # Paths
10
  BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
11
  DATA_PATH = os.path.join(BASE_DIR, "data")
12
  QDRANT_PATH = os.path.join(BASE_DIR, "VectorDB")
13
 
14
- # Collection Names
15
  COLLECTION_NAME = "rag_input"
16
- # If the router uses specific categories, we should define them or handle them
17
  CATEGORIES = ["ky_thuat", "doanh_nghiep", "chung"]
18
 
19
- # Model Names
20
- # Sử dụng BERT
21
  EMBED_MODEL_NAME = "sentence-transformers/all-MiniLM-L6-v2"
22
  LLM_MODEL_NAME = "gemini-2.5-flash"
23
  RERANK_MODEL_NAME = "cross-encoder/ms-marco-MiniLM-L-6-v2"
@@ -34,6 +28,4 @@ def get_llm(temperature=0.2):
34
  google_api_key=api_key
35
  )
36
 
37
-
38
- # Shared Instances
39
  shared_llm = get_llm()
 
3
  from langchain_google_genai import ChatGoogleGenerativeAI
4
  from langchain_huggingface import HuggingFaceEmbeddings
5
 
 
6
  load_dotenv()
7
 
 
8
  BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
9
  DATA_PATH = os.path.join(BASE_DIR, "data")
10
  QDRANT_PATH = os.path.join(BASE_DIR, "VectorDB")
11
 
 
12
  COLLECTION_NAME = "rag_input"
 
13
  CATEGORIES = ["ky_thuat", "doanh_nghiep", "chung"]
14
 
 
 
15
  EMBED_MODEL_NAME = "sentence-transformers/all-MiniLM-L6-v2"
16
  LLM_MODEL_NAME = "gemini-2.5-flash"
17
  RERANK_MODEL_NAME = "cross-encoder/ms-marco-MiniLM-L-6-v2"
 
28
  google_api_key=api_key
29
  )
30
 
 
 
31
  shared_llm = get_llm()
run.sh CHANGED
@@ -1,16 +1,14 @@
1
  #!/bin/bash
2
 
3
- # Hiển thị màu sắc cho đẹp
4
  GREEN='\033[0;32m'
5
  BLUE='\033[0;34m'
6
  RED='\033[0;31m'
7
- NC='\033[0m' # No Color
8
 
9
  echo -e "${BLUE}=======================================${NC}"
10
  echo -e "${BLUE} MULTIMODAL RAG CHATBOT RUNNER ${NC}"
11
  echo -e "${BLUE}=======================================${NC}"
12
 
13
- # Kiểm tra file .env
14
  if [ ! -f .env ]; then
15
  echo -e "${RED}[!] Không tìm thấy file .env. Vui lòng tạo file .env và thêm GOOGLE_API_KEY.${NC}"
16
  exit 1
 
1
  #!/bin/bash
2
 
 
3
  GREEN='\033[0;32m'
4
  BLUE='\033[0;34m'
5
  RED='\033[0;31m'
6
+ NC='\033[0m'
7
 
8
  echo -e "${BLUE}=======================================${NC}"
9
  echo -e "${BLUE} MULTIMODAL RAG CHATBOT RUNNER ${NC}"
10
  echo -e "${BLUE}=======================================${NC}"
11
 
 
12
  if [ ! -f .env ]; then
13
  echo -e "${RED}[!] Không tìm thấy file .env. Vui lòng tạo file .env và thêm GOOGLE_API_KEY.${NC}"
14
  exit 1