a
    ”˜ëjè	  ã                   @  sn   d Z ddlmZ ddlZddlmZmZmZ dddœdd	„Zdd
dddddœdd„Z	ddddddœdd„Z
dS )z$Utilities for environment variables.é    )ÚannotationsN)ÚAnyÚOptionalÚUnionÚstrÚbool)Úenv_varÚreturnc                 C  s   | t jv ot j|  dvS )zËCheck if an environment variable is set.

    Args:
        env_var (str): The name of the environment variable.

    Returns:
        bool: True if the environment variable is set, False otherwise.
    >   Ú ÚFalseÚ0Úfalse)ÚosÚenviron)r   © r   úW/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/langchain_core/utils/env.pyÚenv_var_is_set	   s    	r   zdict[str, Any]zUnion[str, list[str]]zOptional[str])ÚdataÚkeyÚenv_keyÚdefaultr	   c                 C  sx   t |ttfƒr.|D ]}|  |¡ }r|  S qt |tƒrP|| v rP| | rP| | S t |ttfƒrf|d n|}t|||d�S )a  Get a value from a dictionary or an environment variable.

    Args:
        data: The dictionary to look up the key in.
        key: The key to look up in the dictionary. This can be a list of keys to try
            in order.
        env_key: The environment variable to look up if the key is not
            in the dictionary.
        default: The default value to return if the key is not in the dictionary
            or the environment. Defaults to None.

    Returns:
        The dict value or the environment variable value.
    r   )r   )Ú
isinstanceÚlistÚtupleÚgetr   Úget_from_env)r   r   r   r   ÚkÚvalueZkey_for_errr   r   r   Úget_from_dict_or_env   s    
r   )r   r   r   r	   c                 C  sB   t  |¡ }r|S |dur|S d| › d|› d| › d�}t|ƒ‚dS )a3  Get a value from a dictionary or an environment variable.

    Args:
        key: The key to look up in the dictionary.
        env_key: The environment variable to look up if the key is not
            in the dictionary.
        default: The default value to return if the key is not in the dictionary
            or the environment. Defaults to None.

    Returns:
        str: The value of the key.

    Raises:
        ValueError: If the key is not in the dictionary and no default value is
            provided or if the environment variable is not set.
    NzDid not find z&, please add an environment variable `z` which contains it, or pass `z` as a named parameter.)r   ÚgetenvÚ
ValueError)r   r   r   Z	env_valueÚmsgr   r   r   r   ;   s    ÿþÿr   )N)N)Ú__doc__Ú
__future__r   r   Útypingr   r   r   r   r   r   r   r   r   r   Ú<module>   s    ü!