From 9399ff6203d83de103998f2e2a8b4a5e33361fdb Mon Sep 17 00:00:00 2001 From: codebanesr Date: Sat, 16 Sep 2023 12:18:44 +0300 Subject: [PATCH 1/2] updating nginx config file --- nginx/nginx.conf | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 296712b1d..14c091271 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; + } location /backend/ { proxy_pass http://backend:5000/; @@ -24,4 +28,4 @@ http { proxy_pass http://dashboard:8000/; } } -} +} \ No newline at end of file From fd318a16271c1aa78291ac6e47d1f5d82d2f7b07 Mon Sep 17 00:00:00 2001 From: codebanesr Date: Sat, 16 Sep 2023 13:10:33 +0300 Subject: [PATCH 2/2] fixing url issues when running inside container --- llm-server/.env.example | 3 ++- llm-server/app.py | 4 ---- llm-server/utils/db.py | 35 +++++++++++++++++++++-------------- nginx/nginx.conf | 2 +- 4 files changed, 24 insertions(+), 20 deletions(-) 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 14c091271..484f3c1f9 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -9,7 +9,7 @@ http { listen 80; location /backend/flows/ { rewrite /backend/flows/(.*) /workflow/$1 break; - proxy_pass http://llm-server; + proxy_pass http://llm-server:8002/; } location /backend/ {