aiq.llm.utils.env_config_value#

Classes#

EnvConfigValueSource

Create a collection of name/value pairs.

EnvConfigValue

A wrapper for a string used as a configuration value which can be loaded from the system environment or injected via

Module Contents#

class EnvConfigValueSource(*args, **kwds)#

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

ENV_DEFAULT = 1#
CONSTRUCTOR = 2#
ENV_OVERRIDE = 3#
class EnvConfigValue(value: str | None = None, use_env: bool = True)#

Bases: abc.ABC

A wrapper for a string used as a configuration value which can be loaded from the system environment or injected via the constructor. This class should be subclassed and the class fields _ENV_KEY and _ENV_KEY_OVERRIDE can be set to enable environment-loading functionality. Convienience properties are available to check from where the value was loaded.

Parameters#

valuestr, optional

The value to be contained in the EnvConfigValue. If the value is None, an attempt will be made to load it from the environment using _ENV_KEY. if the _ENV_KEY_OVERRIDE field is not None, an attempt will be made to load that environment variable in place of the passed-in value.

use_envbool

If False, all environment-loading logic will be bypassed and the passed-in value will be used as-is. defaults to True.

_ENV_KEY: str | None = None#
_ENV_KEY_OVERRIDE: str | None = None#
_ALLOW_NONE: bool = False#
_source#
_value = None#
_use_env = True#
property source: EnvConfigValueSource#
property use_env: bool#
property value: str | None#