配置
lazyllm.Config
Bases: object
Config is a configuration class provided by LazyLLM, which loads configurations of LazyLLM framework from config files, environment variables, or specify them explicitly. it can export all configuration items as well. The Config module automatically generates an object named 'config' containing all configurations.
Parameters:
-
prefix(str, default:'LAZYLLM') –Environment variable prefix. Defaults to 'LAZYLLM'
-
home(str, default:join(expanduser('~'), '.lazyllm')) –Configuration file directory path. Defaults to '~/.lazyllm'
Source code in lazyllm/configs.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
done()
Check if any configuration items in the config.json file that is not loaded by the add method.
Source code in lazyllm/configs.py
getenv(name, type, default=None)
Get value of LazyLLM-related environment variables.
Parameters:
-
name(str) –The name of the environment variable (without the prefix), case-insensitive. The function obtains value
-
type(type) –Specifies the type of the configuration, for example, str. For boolean types, the function will
-
default(optional, default:None) –If the value of the environment variable cannot be obtained, this value is returned.
Source code in lazyllm/configs.py
add(name, type, default=None, env=None, *, options=None)
Loads value into LazyLLM configuration item. The function first attempts to find the value with the given name from the dict loaded from config.json. If found, it removes the key from the dict and saves the value to the config. If 'env' is a string, the function calls getenv to look for the corresponding LazyLLM environment variable, and if it's found, writes it to the config. If 'env' is a dictionary, the function attempts to call getenv to find the environment variables corresponding to the keys in the dict and convert them to boolean type. If the converted boolean value is True, the value corresponding to the current key in the dict is written to the config.
Parameters:
-
name(str) –The name of the configuration item
-
type(type) –The type of the configuration
-
default(optional, default:None) –The default value of the configuration if no value can be obtained
-
env(optional, default:None) –The name of the environment variable without the prefix, or a dictionary where the keys are the
Source code in lazyllm/configs.py
get_all_configs()
Get all configurations from the config.
Examples:
>>> import lazyllm
>>> from lazyllm.configs import config
>>> config['launcher']
'empty'
>>> config.get_all_configs()
{'home': '~/.lazyllm/', 'mode': <Mode.Normal: (1,)>, 'repr_ml': False, 'rag_store': 'None', 'redis_url': 'None', ...}
Source code in lazyllm/configs.py
get_config(cfg)
staticmethod
Static method: Get configuration from config dictionary. This is a simple configuration retrieval method mainly used to extract configuration information from already loaded configuration dictionaries.
Parameters:
-
cfg(dict) –The configuration dictionary read from the config file.
Source code in lazyllm/configs.py
temp(name, value)
Context manager for temporary configuration modification.
Temporarily modifies the value of the specified configuration item within the with statement block, and automatically restores the original value when exiting the block.
Parameters:
-
name(str) –The name of the configuration item to temporarily change.
-
value(Any) –The temporary value to set.
Source code in lazyllm/configs.py
refresh(targets=None)
Refresh configuration items based on the latest environment variable values.
If targets is a string, updates the single corresponding configuration item;
if it's a list, updates multiple;
if None, scans all environment-variable-mapped configuration items and updates them.
Parameters:
-
targets(str | list[str] | None, default:None) –Name of the config key or list of keys to refresh, or None to refresh all environment-backed keys.