From 5ed04de27e27deed1dc460731de59761ceb0d65f Mon Sep 17 00:00:00 2001 From: Vasilije <8619304+Vasilije1990@users.noreply.github.com> Date: Thu, 21 Dec 2023 18:49:07 +0100 Subject: [PATCH] Make sure that secrets would work on aws --- .env.template | 2 +- cognitive_architecture/config.py | 23 ++++++++++++++--- .../database/create_database.py | 25 ++++++++++--------- .../database/postgres/database.py | 19 ++++++-------- .../database/vectordb/vectordb.py | 2 +- entrypoint.sh | 1 + main.py | 2 +- 7 files changed, 45 insertions(+), 29 deletions(-) diff --git a/.env.template b/.env.template index e7eff9d51..36995410c 100644 --- a/.env.template +++ b/.env.template @@ -1,7 +1,7 @@ OPENAI_API_KEY=sk WEAVIATE_URL = WEAVIATE_API_KEY = -ENVIRONMENT = docker +ENV = docker POSTGRES_USER = bla POSTGRES_PASSWORD = bla POSTGRES_DB = bubu diff --git a/cognitive_architecture/config.py b/cognitive_architecture/config.py index c2694f637..9cd4e923b 100644 --- a/cognitive_architecture/config.py +++ b/cognitive_architecture/config.py @@ -31,12 +31,29 @@ class Config: embedding_chunk_size: int = 300 # Database parameters - graph_database_url: str = os.getenv('GRAPH_DB_URL') - graph_database_username: str = os.getenv('GRAPH_DB_USER') - graph_database_password: str = os.getenv('GRAPH_DB_PW') + if os.getenv('ENV') == 'prod' or os.getenv('ENV') == 'dev' or os.getenv('AWS_ENV') == 'dev' or os.getenv('AWS_ENV') == 'prd': + graph_database_url: str = os.getenv('GRAPH_DB_URL_PROD') + graph_database_username: str = os.getenv('GRAPH_DB_USER') + graph_database_password: str = os.getenv('GRAPH_DB_PW_PROD') + else: + graph_database_url: str = os.getenv('GRAPH_DB_URL') + graph_database_username: str = os.getenv('GRAPH_DB_USER') + graph_database_password: str = os.getenv('GRAPH_DB_PW') weaviate_url: str = os.getenv('WEAVIATE_URL') weaviate_api_key: str = os.getenv('WEAVIATE_API_KEY') + postgres_user: str = os.getenv('POSTGRES_USER') + postgres_password: str = os.getenv('POSTGRES_PASSWORD') + postgres_db: str = os.getenv('POSTGRES_DB') + if os.getenv('ENV') == 'prod' or os.getenv('ENV') == 'dev' or os.getenv('AWS_ENV') == 'dev' or os.getenv('AWS_ENV') == 'prd': + postgres_host: str = os.getenv('POSTGRES_PROD_HOST') + elif os.getenv('ENV') == 'docker': + postgres_host: str = os.getenv('POSTGRES_HOST_DOCKER') + elif os.getenv('ENV') == 'local': + postgres_host: str = os.getenv('POSTGRES_HOST_LOCAL') + + + # Client ID diff --git a/cognitive_architecture/database/create_database.py b/cognitive_architecture/database/create_database.py index 578d80b15..ac9c3a852 100644 --- a/cognitive_architecture/database/create_database.py +++ b/cognitive_architecture/database/create_database.py @@ -9,6 +9,10 @@ from postgres.models import operation from postgres.models import sessions from postgres.models import user from postgres.models import docs +from cognitive_architecture.config import Config +config = Config() +config.load() + from postgres.database import Base @@ -54,18 +58,15 @@ def create_tables(engine): Base.metadata.create_all(bind=engine) if __name__ == "__main__": - username = os.getenv('POSTGRES_USER') - password = os.getenv('POSTGRES_PASSWORD') - database_name = os.getenv('POSTGRES_DB') - environment = os.environ.get("ENVIRONMENT") - - if environment == "local": - host = os.getenv('POSTGRES_HOST') - - elif environment == "docker": - host = os.getenv('POSTGRES_HOST_DOCKER') - else: - host = os.getenv('POSTGRES_HOST_DOCKER') + # + # username = os.getenv('POSTGRES_USER') + # password = os.getenv('POSTGRES_PASSWORD') + # database_name = os.getenv('POSTGRES_DB') + # environment = os.environ.get("ENV") + host = config.postgres_host + username = config.postgres_user + password = config.postgres_password + database_name = config.postgres_db engine = create_admin_engine(username, password, host, database_name) diff --git a/cognitive_architecture/database/postgres/database.py b/cognitive_architecture/database/postgres/database.py index c5ff46dbe..3d3bd61f5 100644 --- a/cognitive_architecture/database/postgres/database.py +++ b/cognitive_architecture/database/postgres/database.py @@ -15,26 +15,23 @@ load_dotenv() # # Get the parent directory of your script and add it to sys.path # parent_dir = os.path.dirname(script_dir) # sys.path.append(parent_dir) +from cognitive_architecture.config import Config +config = Config() +config.load() # in seconds MAX_RETRIES = 3 RETRY_DELAY = 5 -username = os.getenv('POSTGRES_USER') -password = os.getenv('POSTGRES_PASSWORD') -database_name = os.getenv('POSTGRES_DB') -import os -environment = os.environ.get("ENVIRONMENT") -if environment == "local": - host= os.getenv('POSTGRES_HOST') +host = config.postgres_host +username = config.postgres_user +password = config.postgres_password +database_name = config.postgres_db + -elif environment == "docker": - host= os.getenv('POSTGRES_HOST_DOCKER') -else: - host= os.getenv('POSTGRES_HOST_DOCKER') diff --git a/cognitive_architecture/database/vectordb/vectordb.py b/cognitive_architecture/database/vectordb/vectordb.py index 0b4c759ce..255e8e763 100644 --- a/cognitive_architecture/database/vectordb/vectordb.py +++ b/cognitive_architecture/database/vectordb/vectordb.py @@ -169,7 +169,7 @@ class WeaviateVectorDB(VectorDB): else: chunk_count = 0 from cognitive_architecture.database.vectordb.chunkers.chunkers import chunk_data - documents = [chunk_data(chunk_strategy="VANILLA", source_data=observation, chunk_size=50, + documents = [chunk_data(chunk_strategy="VANILLA", source_data=observation, chunk_size=300, chunk_overlap=20)] for doc in documents[0]: chunk_count += 1 diff --git a/entrypoint.sh b/entrypoint.sh index 300813101..9c4075106 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,5 +1,6 @@ #!/bin/bash export ENVIRONMENT +export ENV # Run Python scripts with error handling echo "Running fetch_secret.py" python cognitive_architecture/fetch_secret.py diff --git a/main.py b/main.py index cc98eb8ad..eaf7085e9 100644 --- a/main.py +++ b/main.py @@ -320,7 +320,7 @@ async def user_context_enrichment(session, user_id:str, query:str)->str: final_result = generate_graph(entire_context) logging.info("Final result is %s", final_result) - return final_result + return final_result.response