From 95f848822782b5082b3796c1b1830ad5d46a36e0 Mon Sep 17 00:00:00 2001 From: Niklas Mueller Date: Sat, 15 Jun 2024 17:01:42 +0200 Subject: [PATCH] basic structure setup --- .env | 47 ++++++++++++++++++++ .gitignore | 1 + README.md | 24 ++++++++++- docker-compose.yaml | 67 +++++++++++++++++++++++++++++ rag-chat-backend/Dockerfile | 15 +++++++ rag-chat-backend/requirements.txt | 11 +++++ rag-chat-backend/src/__init__.py | 0 rag-chat-backend/src/app.py | 30 +++++++++++++ rag-chat-backend/src/core/config.py | 7 +++ 9 files changed, 200 insertions(+), 2 deletions(-) create mode 100644 .env create mode 100644 .gitignore create mode 100644 docker-compose.yaml create mode 100644 rag-chat-backend/Dockerfile create mode 100644 rag-chat-backend/requirements.txt create mode 100644 rag-chat-backend/src/__init__.py create mode 100644 rag-chat-backend/src/app.py create mode 100644 rag-chat-backend/src/core/config.py diff --git a/.env b/.env new file mode 100644 index 0000000..7fe3903 --- /dev/null +++ b/.env @@ -0,0 +1,47 @@ + +################################ +# General Settings +################################ +LOGGING_LEVEL=DEBUG + + +################################ +# Object Storage Settings +################################ + +# NOTE! MinIO requires an key at least consisting of 8 chars for the secret key +S3_ENDPOINT=http://localhost:9000 +S3_ACCESS_KEY=admin +S3_SECRET_KEY=secret-admin-key +BUCKET_NAME=rag-bucket + + +################################ +# Vector DB Settings +################################ + +VECTOR_STORE_ENDPOINT=localhost +VECTOR_STORE_PORT=9200 + +OPENSEARCH_USE_SSL=True + + +################################ +# LLM Settings +################################ + +# Which LLm to use +LLM_OPTION=ollamallm + +# LLM_API_ENDPOINT=http://:11434 +LLM_API_ENDPOINT=http://127.0.0.1:11434 + +# if required for you llm setup (for self hosted ollama not needed) +LLM_API_KEY=placeholder + +# valid Language options - "en" "de" "multi" +LLM_LANGUAGE=de + +# LLM Model to be used - "mistral", "phi3", "llama3", etc. +LLM_MODEL_NAME=mistral + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..600d2d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode \ No newline at end of file diff --git a/README.md b/README.md index 857c844..6ca0a8b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,23 @@ -# rag-chat +# RAG-Chat -Chat with your Documents/Knowledgebase \ No newline at end of file +Chat with your Documents/Knowledgebase + + +## Usage + +Clone the repo, enter it and run: + +``` +podman-compose -f docker-compose.yaml up +``` + +## Structure + +### Object Storage +* Minio (http://localhost:9001/) + +### Vector Storage +* OpenSearch (Dashboard under: http://localhost:5601/) + +### RAG-Backend +* API-Docs http://localhost:8000/docs diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..71b91e5 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,67 @@ +version: '3.4' +services: + opensearch-node: + image: docker.io/opensearchproject/opensearch:2.11.1 + container_name: opensearch-node + environment: + - discovery.type=single-node + - bootstrap.memory_lock=true + - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx2g" + ports: + - 9200:9200 + - 9300:9300 + networks: + - rag + volumes: + - opensearch-data:/usr/share/opensearch/data + + opensearch-dashboards: + image: docker.io/opensearchproject/opensearch-dashboards:2.11.1 + container_name: opensearch-dashboards + ports: + - 5601:5601 + expose: + - "5601" + environment: + OPENSEARCH_HOSTS: 'https://opensearch-node:9200' + networks: + - rag + + minio: + container_name: minio + image: docker.io/minio/minio + ports: + - "9000:9000" + - "9001:9001" + volumes: + - minio_storage:/data + - ./init-scripts:/docker-entrypoint-initdb.d + environment: + MINIO_ROOT_USER: ${S3_ACCESS_KEY} + MINIO_ROOT_PASSWORD: ${S3_SECRET_KEY} + command: server --console-address ":9001" /data + networks: + - rag + + backend: + container_name: rag-chat-backend + build: + context: ./rag-chat-backend + dockerfile: Dockerfile + image: rag-chat-backend:0.1 + ports: + - "8000:8000" + environment: + - VECTOR_STORE_ENDPOINT=opensearch-node + - S3_ENDPOINT=http://minio:9000 + env_file: + - .env + networks: + - rag +networks: + rag: {} + + +volumes: + opensearch-data: + minio_storage: {} diff --git a/rag-chat-backend/Dockerfile b/rag-chat-backend/Dockerfile new file mode 100644 index 0000000..5a82d99 --- /dev/null +++ b/rag-chat-backend/Dockerfile @@ -0,0 +1,15 @@ +FROM python:3.10-slim + +WORKDIR /app + +COPY ./requirements.txt /app + +RUN apt-get update && apt-get install -y build-essential +RUN pip install --upgrade pip +RUN pip install -r requirements.txt + +EXPOSE 8000 + +COPY . /app + +CMD ["python", "src/app.py"] diff --git a/rag-chat-backend/requirements.txt b/rag-chat-backend/requirements.txt new file mode 100644 index 0000000..5741cf6 --- /dev/null +++ b/rag-chat-backend/requirements.txt @@ -0,0 +1,11 @@ +uvicorn==0.22.0 +fastapi==0.109.1 + +minio==7.1.17 + +opensearch-py==2.3.2 +opensearch-logger==1.3.0 + +python-dotenv==1.0.0 +python-multipart==0.0.7 +PyPDF2==3.0.1 diff --git a/rag-chat-backend/src/__init__.py b/rag-chat-backend/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rag-chat-backend/src/app.py b/rag-chat-backend/src/app.py new file mode 100644 index 0000000..3f16c64 --- /dev/null +++ b/rag-chat-backend/src/app.py @@ -0,0 +1,30 @@ +"""FastAPI Backend""" + +import uvicorn +import os + +from fastapi import FastAPI +from fastapi.middleware.cors import CORSMiddleware +from dotenv import load_dotenv + +from core.config import settings + +load_dotenv() +app = FastAPI() + +app.add_middleware( + CORSMiddleware, + allow_origins=["*"], + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + +print('OPENSEARCH_USE_SSL') +print(os.getenv('OPENSEARCH_USE_SSL')) +print('settings.API_V1_STR') +print(settings.API_V1_STR) + + +if __name__ == "__main__": + uvicorn.run("app:app", host="0.0.0.0", port=8000, reload=True) diff --git a/rag-chat-backend/src/core/config.py b/rag-chat-backend/src/core/config.py new file mode 100644 index 0000000..420e4d6 --- /dev/null +++ b/rag-chat-backend/src/core/config.py @@ -0,0 +1,7 @@ +# config.py + +class Settings: + API_V1_STR: str = "/api" + + +settings = Settings()