Skip to main content

config.py

Source: sunholo/utils/config.py

Functions

load_config(filename: str = None) -> tuple[dict, str]

Load configuration from a yaml or json file. Will look relative to _CONFIG_FOLDER environment variable if available, else current directory.

Args: filename (str, optional): The name of the configuration file. Defaults to the _CONFIG_FILE environment variable.

Returns: tuple[dict, str]: The configuration as a dictionary and the derived absolute filename.

Example:

config, filename = load_config('config.yaml')
print(f'Config: {config}')
print(f'Loaded from file: {filename}')

load_config_key(key: str, vector_name: str, kind: str)

Load a specific key from a configuration file.

Args: key (str): The key to fetch from the configuration. vector_name (str): The name of the vector in the configuration file. kind: (str, optional): Specify the type of configuration to retrieve e.g. 'vacConfig' which will pick from files within _CONFIG_FOLDER

Returns: str: The value associated with the specified key.

Example:

api_url = load_config_key('apiUrl', 'myVector', kind="vacConfig")
print(f'API URL: {api_url}')

load_all_configs()

Load all configuration files from the specified directory into a dictionary. Files are expected to be either YAML or JSON and must contain a 'kind' key at the root. Caching is used to avoid reloading files within a 5-minute window.

get_module_filepath(filepath: str)

Get the absolute path of a module file based on its relative path.

Args: filepath (str): The relative path of the file.

Returns: str: The absolute file path.

Example:

abs_path = get_module_filepath('config/config.yaml')
print(f'Absolute path: {abs_path}')

reload_config_file(config_file, filename)

Helper function to load a config file and update the cache.

Sunholo Multivac

Get in touch to see if we can help with your GenAI project.

Contact us

Other Links

Sunholo Multivac - GenAIOps

Copyright ©

Holosun ApS 2024