Spaces:
Sleeping
Sleeping
增加load_environ_to_config,全面支持环境变量替换config
Browse files- modules/config.py +15 -0
modules/config.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
from collections import defaultdict
|
| 2 |
from contextlib import contextmanager
|
|
|
|
| 3 |
import os
|
| 4 |
import logging
|
| 5 |
import sys
|
|
@@ -47,6 +48,19 @@ def load_config_to_environ(key_list):
|
|
| 47 |
if key in config:
|
| 48 |
os.environ[key.upper()] = os.environ.get(key.upper(), config[key])
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
hide_history_when_not_logged_in = config.get(
|
| 51 |
"hide_history_when_not_logged_in", False)
|
| 52 |
check_update = config.get("check_update", True)
|
|
@@ -143,6 +157,7 @@ os.environ["ERNIE_APIKEY"] = ernie_api_key
|
|
| 143 |
ernie_secret_key = config.get("ernie_secret_key", "")
|
| 144 |
os.environ["ERNIE_SECRETKEY"] = ernie_secret_key
|
| 145 |
|
|
|
|
| 146 |
load_config_to_environ(["openai_api_type", "azure_openai_api_key", "azure_openai_api_base_url",
|
| 147 |
"azure_openai_api_version", "azure_deployment_name", "azure_embedding_deployment_name", "azure_embedding_model_name"])
|
| 148 |
|
|
|
|
| 1 |
from collections import defaultdict
|
| 2 |
from contextlib import contextmanager
|
| 3 |
+
from json import JSONDecodeError
|
| 4 |
import os
|
| 5 |
import logging
|
| 6 |
import sys
|
|
|
|
| 48 |
if key in config:
|
| 49 |
os.environ[key.upper()] = os.environ.get(key.upper(), config[key])
|
| 50 |
|
| 51 |
+
|
| 52 |
+
def load_environ_to_config():
|
| 53 |
+
global config
|
| 54 |
+
for key, value in os.environ.items():
|
| 55 |
+
try:
|
| 56 |
+
config[key.lower()] = json.loads(value)
|
| 57 |
+
except Exception as e:
|
| 58 |
+
config[key.lower()] = value
|
| 59 |
+
pass
|
| 60 |
+
finally:
|
| 61 |
+
logging.info(f"加载环境变量{key}...")
|
| 62 |
+
|
| 63 |
+
|
| 64 |
hide_history_when_not_logged_in = config.get(
|
| 65 |
"hide_history_when_not_logged_in", False)
|
| 66 |
check_update = config.get("check_update", True)
|
|
|
|
| 157 |
ernie_secret_key = config.get("ernie_secret_key", "")
|
| 158 |
os.environ["ERNIE_SECRETKEY"] = ernie_secret_key
|
| 159 |
|
| 160 |
+
load_environ_to_config()
|
| 161 |
load_config_to_environ(["openai_api_type", "azure_openai_api_key", "azure_openai_api_base_url",
|
| 162 |
"azure_openai_api_version", "azure_deployment_name", "azure_embedding_deployment_name", "azure_embedding_model_name"])
|
| 163 |
|