From 47e5d5684ace8edd27172b5ad7d72d2ddb2bdc53 Mon Sep 17 00:00:00 2001 From: Serj Date: Sat, 29 Apr 2023 15:50:02 +0100 Subject: [PATCH] Replace other env variables in the file --- application/app.py | 14 +++++++------- application/core/settings.py | 6 ++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/application/app.py b/application/app.py index 1185b1a6..e8505442 100644 --- a/application/app.py +++ b/application/app.py @@ -70,20 +70,20 @@ with open("prompts/chat_combine_prompt.txt", "r") as f: with open("prompts/chat_reduce_prompt.txt", "r") as f: chat_reduce_template = f.read() -if os.getenv("API_KEY") is not None: +if settings.API_KEY is not None: api_key_set = True else: api_key_set = False -if os.getenv("EMBEDDINGS_KEY") is not None: +if settings.EMBEDDINGS_KEY is not None: embeddings_key_set = True else: embeddings_key_set = False app = Flask(__name__) app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER = "inputs" -app.config['CELERY_BROKER_URL'] = os.getenv("CELERY_BROKER_URL") -app.config['CELERY_RESULT_BACKEND'] = os.getenv("CELERY_RESULT_BACKEND") -app.config['MONGO_URI'] = os.getenv("MONGO_URI") +app.config['CELERY_BROKER_URL'] = settings.CELERY_BROKER_URL +app.config['CELERY_RESULT_BACKEND'] = settings.CELERY_RESULT_BACKEND +app.config['MONGO_URI'] = settings.MONGO_URI celery = Celery() celery.config_from_object('celeryconfig') mongo = MongoClient(app.config['MONGO_URI']) @@ -126,11 +126,11 @@ def api_answer(): if not api_key_set: api_key = data["api_key"] else: - api_key = os.getenv("API_KEY") + api_key = settings.API_KEY if not embeddings_key_set: embeddings_key = data["embeddings_key"] else: - embeddings_key = os.getenv("EMBEDDINGS_KEY") + embeddings_key = settings.EMBEDDINGS_KEY # use try and except to check for exception try: diff --git a/application/core/settings.py b/application/core/settings.py index de1cbabb..6106aa9b 100644 --- a/application/core/settings.py +++ b/application/core/settings.py @@ -6,6 +6,12 @@ class Settings(BaseSettings): LLM_NAME: str = "openai_chat" EMBEDDINGS_NAME: str = "openai_text-embedding-ada-002" openai_token: str + CELERY_BROKER_URL: str + CELERY_RESULT_BACKEND: str + MONGO_URI: str + + API_KEY: str = None + EMBEDDINGS_KEY: str = None path = Path(__file__).parent.parent.absolute()