Förbättrat utläsning av data från konfigurationsfilen smartassist.yaml
This commit is contained in:
@@ -31,15 +31,22 @@ def configure():
|
||||
return os.getenv(env_var_name, None)
|
||||
return value
|
||||
|
||||
def update_dict_with_env_vars(d):
|
||||
for key in d:
|
||||
if isinstance(d[key], dict):
|
||||
update_dict_with_env_vars(d[key]) # Recursively check nested dictionaries
|
||||
elif isinstance(d[key], str):
|
||||
d[key] = resolve_env_var(d[key])
|
||||
def update_value(value):
|
||||
if isinstance(value, dict): # Dictionaries need recursive check
|
||||
return update_dict_with_env_vars(value)
|
||||
elif isinstance(value, list): # Lists must be traversed element by element
|
||||
return [update_value(item) for item in value]
|
||||
elif isinstance(value, str): # If value is a string it might be an environmnet variable
|
||||
return resolve_env_var(value)
|
||||
else: # Anything else, just keep the old value
|
||||
return value
|
||||
|
||||
def update_dict_with_env_vars(d): # Check all keys in d
|
||||
for key in d: # Iterate over all keys in the dictionary. The keys seen are all at the same level
|
||||
logger.info(f"key investigated now: {key}")
|
||||
d[key] = update_value(d[key])
|
||||
return d
|
||||
|
||||
# Update the config dictionary with resolved environment variables
|
||||
updated_config = update_dict_with_env_vars(config)
|
||||
|
||||
####################################
|
||||
@@ -64,7 +71,6 @@ def configure():
|
||||
logger.debug(f"Constructing endpoint address as url+api: {url+api}")
|
||||
global_state.set_backend_api_ep(url+api) # Extract API endpoint if defined and set in global_state
|
||||
logger.debug(f"Backend API endpoint is set to {global_state.get_backend_api_ep()}")
|
||||
# os.environ['BE_API_ENDPOINT'] = backend_api_ep # Look into alternative way to share this with backend.py
|
||||
|
||||
####################################
|
||||
# Extract Ollama parameters (url, api_key, model)
|
||||
|
||||
Reference in New Issue
Block a user