From d58de061fac0aed51a72ae90875ebc3ac58af0d2 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Mon, 19 Feb 2024 18:54:22 -0800 Subject: [PATCH 1/3] feat: config.json support --- backend/config.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/backend/config.py b/backend/config.py index b80bc081..fff5683f 100644 --- a/backend/config.py +++ b/backend/config.py @@ -5,6 +5,8 @@ from secrets import token_bytes from base64 import b64encode from constants import ERROR_MESSAGES from pathlib import Path +import json + try: from dotenv import load_dotenv, find_dotenv @@ -28,6 +30,13 @@ ENV = os.environ.get("ENV", "dev") DATA_DIR = str(Path(os.getenv("DATA_DIR", "./data")).resolve()) FRONTEND_BUILD_DIR = str(Path(os.getenv("FRONTEND_BUILD_DIR", "../build"))) +try: + with open(f"{DATA_DIR}/config.json", "r") as f: + CONFIG_DATA = json.load(f) +except: + CONFIG_DATA = {} + +print(CONFIG_DATA) #################################### # File Upload DIR #################################### @@ -80,9 +89,12 @@ if OPENAI_API_BASE_URL == "": ENABLE_SIGNUP = os.environ.get("ENABLE_SIGNUP", True) DEFAULT_MODELS = os.environ.get("DEFAULT_MODELS", None) -DEFAULT_PROMPT_SUGGESTIONS = os.environ.get( - "DEFAULT_PROMPT_SUGGESTIONS", - [ + + +DEFAULT_PROMPT_SUGGESTIONS = ( + CONFIG_DATA["ui"]["prompt_suggestions"] + if "ui" in CONFIG_DATA and "prompt_suggestions" in CONFIG_DATA["ui"] + else [ { "title": ["Help me study", "vocabulary for a college entrance exam"], "content": "Help me study vocabulary: write a sentence for me to fill in the blank, and I'll try to pick the correct option.", @@ -99,8 +111,10 @@ DEFAULT_PROMPT_SUGGESTIONS = os.environ.get( "title": ["Show me a code snippet", "of a website's sticky header"], "content": "Show me a code snippet of a website's sticky header in CSS and JavaScript.", }, - ], + ] ) + + DEFAULT_USER_ROLE = "pending" USER_PERMISSIONS = {"chat": {"deletion": True}} From daa989b7dc7fdc956a7b2861a85e03f187a1cf0a Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Mon, 19 Feb 2024 19:09:09 -0800 Subject: [PATCH 2/3] feat: validate type --- backend/config.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/config.py b/backend/config.py index fff5683f..8167d4f1 100644 --- a/backend/config.py +++ b/backend/config.py @@ -36,7 +36,6 @@ try: except: CONFIG_DATA = {} -print(CONFIG_DATA) #################################### # File Upload DIR #################################### @@ -93,7 +92,9 @@ DEFAULT_MODELS = os.environ.get("DEFAULT_MODELS", None) DEFAULT_PROMPT_SUGGESTIONS = ( CONFIG_DATA["ui"]["prompt_suggestions"] - if "ui" in CONFIG_DATA and "prompt_suggestions" in CONFIG_DATA["ui"] + if "ui" in CONFIG_DATA + and "prompt_suggestions" in CONFIG_DATA["ui"] + and type(CONFIG_DATA["ui"]["prompt_suggestions"]) is list else [ { "title": ["Help me study", "vocabulary for a college entrance exam"], From 3d10f21b3b8d2ede724b2499c18dfcbeb560db8f Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Mon, 19 Feb 2024 19:28:34 -0800 Subject: [PATCH 3/3] feat: include default config.json --- backend/.gitignore | 1 + backend/data/config.json | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 backend/data/config.json diff --git a/backend/.gitignore b/backend/.gitignore index 4dd0b849..16180123 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -7,4 +7,5 @@ uploads _test Pipfile data/* +!data/config.json .webui_secret_key \ No newline at end of file diff --git a/backend/data/config.json b/backend/data/config.json new file mode 100644 index 00000000..ad32624f --- /dev/null +++ b/backend/data/config.json @@ -0,0 +1,34 @@ +{ + "ui": { + "prompt_suggestions": [ + { + "title": [ + "Help me study", + "vocabulary for a college entrance exam" + ], + "content": "Help me study vocabulary: write a sentence for me to fill in the blank, and I'll try to pick the correct option." + }, + { + "title": [ + "Give me ideas", + "for what to do with my kids' art" + ], + "content": "What are 5 creative things I could do with my kids' art? I don't want to throw them away, but it's also so much clutter." + }, + { + "title": [ + "Tell me a fun fact", + "about the Roman Empire" + ], + "content": "Tell me a random fun fact about the Roman Empire" + }, + { + "title": [ + "Show me a code snippet", + "of a website's sticky header" + ], + "content": "Show me a code snippet of a website's sticky header in CSS and JavaScript." + }, + ] + } +} \ No newline at end of file