diff --git a/llm-server/.env.example b/llm-server/.env.example index a33e3a927..41c9a9aa1 100644 --- a/llm-server/.env.example +++ b/llm-server/.env.example @@ -3,7 +3,8 @@ OPENAI_API_TYPE=openai OPENAI_API_KEY= PINECONE_API_KEY= PINECONE_ENV= -MONGODB_URL=mongodb://mongodb:27017/opencopilot +# MONGODB_URL=mongodb://dbuser:dbpass@mongodb:27017/opencopilot?authSource=admin&retryWrites=true&w=majority +MONGODB_URL=mongodb://dbuser:dbpass@localhost:27017/opencopilot?authSource=admin&retryWrites=true&w=majority QDRANT_URL=http://qdrant:6333 STORE=QDRANT diff --git a/llm-server/app.py b/llm-server/app.py index 3b917081d..6906593ac 100644 --- a/llm-server/app.py +++ b/llm-server/app.py @@ -18,10 +18,6 @@ from prompts.base import api_base_prompt, non_api_base_prompt app = Flask(__name__) -app.config["MONGO_URI"] = os.getenv( - "MONGODB_URL", "mongodb://localhost:27017/opencopilot" -) -mongo = PyMongo(app) app.register_blueprint(workflow, url_prefix="/workflow") diff --git a/llm-server/utils/db.py b/llm-server/utils/db.py index 25c1ca6f0..3ccd2003c 100644 --- a/llm-server/utils/db.py +++ b/llm-server/utils/db.py @@ -1,20 +1,27 @@ # type: ignore from pymongo import MongoClient from pymongo.database import Database as PyMongoDatabase +from dotenv import load_dotenv +import os +load_dotenv() class Database: - _instance: MongoClient = None - - def __new__(cls, app=None): - if cls._instance is None: - cls._instance = super().__new__(cls) - cls._instance.client = MongoClient( - "localhost", 27017, username="dbuser", password="dbpass" - ) - cls._instance.db = cls._instance.client.opencopilot - return cls._instance - - @staticmethod - def get_db() -> PyMongoDatabase: - return Database._instance.db # Access _instance directly from the class + + _instance: MongoClient = None + + def __new__(cls, app=None): + + if cls._instance is None: + cls._instance = super().__new__(cls) + + mongo_url = os.environ.get("MONGODB_URL") + cls._instance.client = MongoClient(mongo_url) + + cls._instance.db = cls._instance.client.opencopilot + + return cls._instance + + @staticmethod + def get_db() -> PyMongoDatabase: + return Database._instance.db \ No newline at end of file diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 296712b1d..484f3c1f9 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -7,6 +7,10 @@ http { server { listen 80; + location /backend/flows/ { + rewrite /backend/flows/(.*) /workflow/$1 break; + proxy_pass http://llm-server:8002/; + } location /backend/ { proxy_pass http://backend:5000/; @@ -24,4 +28,4 @@ http { proxy_pass http://dashboard:8000/; } } -} +} \ No newline at end of file