From df9d432d29c1bbdf28abb3d35d129060b1964dd3 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 24 Apr 2025 17:29:41 +0100 Subject: [PATCH] fix: mongo db database name in settings --- application/agents/base.py | 5 +++-- application/api/answer/routes.py | 2 +- application/api/internal/routes.py | 2 +- application/api/user/routes.py | 2 +- application/core/settings.py | 1 + application/llm/google_ai.py | 3 ++- application/llm/openai.py | 2 +- application/logging.py | 3 ++- application/usage.py | 3 ++- application/worker.py | 4 ++-- 10 files changed, 16 insertions(+), 11 deletions(-) diff --git a/application/agents/base.py b/application/agents/base.py index 64fac17b..e4b76ca1 100644 --- a/application/agents/base.py +++ b/application/agents/base.py @@ -10,6 +10,7 @@ from application.core.mongo_db import MongoDB from application.llm.llm_creator import LLMCreator from application.logging import build_stack_data, log_activity, LogContext from application.retriever.base import BaseRetriever +from application.core.settings import settings from bson.objectid import ObjectId @@ -61,7 +62,7 @@ class BaseAgent(ABC): def _get_tools(self, api_key: str = None) -> Dict[str, Dict]: mongo = MongoDB.get_client() - db = mongo["docsgpt"] + db = mongo[settings.MONGO_DB_NAME] agents_collection = db["agents"] tools_collection = db["user_tools"] @@ -82,7 +83,7 @@ class BaseAgent(ABC): def _get_user_tools(self, user="local"): mongo = MongoDB.get_client() - db = mongo["docsgpt"] + db = mongo[settings.MONGO_DB_NAME] user_tools_collection = db["user_tools"] user_tools = user_tools_collection.find({"user": user, "status": True}) user_tools = list(user_tools) diff --git a/application/api/answer/routes.py b/application/api/answer/routes.py index 8f44385b..2a8476d8 100644 --- a/application/api/answer/routes.py +++ b/application/api/answer/routes.py @@ -23,7 +23,7 @@ from application.utils import check_required_fields, limit_chat_history logger = logging.getLogger(__name__) mongo = MongoDB.get_client() -db = mongo["docsgpt"] +db = mongo[settings.MONGO_DB_NAME] conversations_collection = db["conversations"] sources_collection = db["sources"] prompts_collection = db["prompts"] diff --git a/application/api/internal/routes.py b/application/api/internal/routes.py index f0ad042f..80759593 100755 --- a/application/api/internal/routes.py +++ b/application/api/internal/routes.py @@ -11,7 +11,7 @@ from application.storage.storage_creator import StorageCreator logger = logging.getLogger(__name__) mongo = MongoDB.get_client() -db = mongo["docsgpt"] +db = mongo[settings.MONGO_DB_NAME] conversations_collection = db["conversations"] sources_collection = db["sources"] diff --git a/application/api/user/routes.py b/application/api/user/routes.py index 6b52a436..d9c41c8f 100644 --- a/application/api/user/routes.py +++ b/application/api/user/routes.py @@ -23,7 +23,7 @@ from application.utils import check_required_fields, validate_function_name from application.vectorstore.vector_creator import VectorCreator mongo = MongoDB.get_client() -db = mongo["docsgpt"] +db = mongo[settings.MONGO_DB_NAME] conversations_collection = db["conversations"] sources_collection = db["sources"] prompts_collection = db["prompts"] diff --git a/application/core/settings.py b/application/core/settings.py index c3c5159e..3be34242 100644 --- a/application/core/settings.py +++ b/application/core/settings.py @@ -19,6 +19,7 @@ class Settings(BaseSettings): CELERY_BROKER_URL: str = "redis://localhost:6379/0" CELERY_RESULT_BACKEND: str = "redis://localhost:6379/1" MONGO_URI: str = "mongodb://localhost:27017/docsgpt" + MONGO_DB_NAME: str = "docsgpt" MODEL_PATH: str = os.path.join(current_dir, "models/docsgpt-7b-f16.gguf") DEFAULT_MAX_HISTORY: int = 150 MODEL_TOKEN_LIMITS: dict = { diff --git a/application/llm/google_ai.py b/application/llm/google_ai.py index 06dbbdfd..a56616d2 100644 --- a/application/llm/google_ai.py +++ b/application/llm/google_ai.py @@ -5,6 +5,7 @@ import json from application.llm.base import BaseLLM from application.storage.storage_creator import StorageCreator +from application.core.settings import settings class GoogleLLM(BaseLLM): @@ -120,7 +121,7 @@ class GoogleLLM(BaseLLM): from application.core.mongo_db import MongoDB mongo = MongoDB.get_client() - db = mongo["docsgpt"] + db = mongo[settings.MONGO_DB_NAME] attachments_collection = db["attachments"] if '_id' in attachment: attachments_collection.update_one( diff --git a/application/llm/openai.py b/application/llm/openai.py index e8df92dd..248fd7e2 100644 --- a/application/llm/openai.py +++ b/application/llm/openai.py @@ -291,7 +291,7 @@ class OpenAILLM(BaseLLM): from application.core.mongo_db import MongoDB mongo = MongoDB.get_client() - db = mongo["docsgpt"] + db = mongo[settings.MONGO_DB_NAME] attachments_collection = db["attachments"] if '_id' in attachment: attachments_collection.update_one( diff --git a/application/logging.py b/application/logging.py index 1dd0d557..ed07f858 100644 --- a/application/logging.py +++ b/application/logging.py @@ -7,6 +7,7 @@ import uuid from typing import Any, Callable, Dict, Generator, List from application.core.mongo_db import MongoDB +from application.core.settings import settings logging.basicConfig( level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s" @@ -131,7 +132,7 @@ def _log_to_mongodb( ) -> None: try: mongo = MongoDB.get_client() - db = mongo["docsgpt"] + db = mongo[settings.MONGO_DB_NAME] user_logs_collection = db["stack_logs"] log_entry = { diff --git a/application/usage.py b/application/usage.py index 85328c1f..46620fff 100644 --- a/application/usage.py +++ b/application/usage.py @@ -2,10 +2,11 @@ import sys from datetime import datetime from application.core.mongo_db import MongoDB +from application.core.settings import settings from application.utils import num_tokens_from_object_or_list, num_tokens_from_string mongo = MongoDB.get_client() -db = mongo["docsgpt"] +db = mongo[settings.MONGO_DB_NAME] usage_collection = db["token_usage"] diff --git a/application/worker.py b/application/worker.py index d83639d7..3f542b6a 100755 --- a/application/worker.py +++ b/application/worker.py @@ -26,7 +26,7 @@ from application.parser.chunking import Chunker from application.utils import count_tokens_docs mongo = MongoDB.get_client() -db = mongo["docsgpt"] +db = mongo[settings.MONGO_DB_NAME] sources_collection = db["sources"] # Constants @@ -356,7 +356,7 @@ def attachment_worker(self, file_info, user): """ mongo = MongoDB.get_client() - db = mongo["docsgpt"] + db = mongo[settings.MONGO_DB_NAME] attachments_collection = db["attachments"] filename = file_info["filename"]