config_list_from_dotenv - AG2
config_list_from_dotenv
``autogen.config_list_from_dotenv #
config_list_from_dotenv(dotenv_file_path=None, model_api_key_map=None, filter_dict=None)
Load API configurations from a specified .env file or environment variables and construct a list of configurations.
This function will:
- Load API keys from a provided .env file or from existing environment variables.
- Create a configuration dictionary for each model using the API keys and additional configurations.
- Filter and return the configurations based on provided filters.
model_api_key_map will default to { "gpt-4": "OPENAI_API_KEY", "gpt-3.5-turbo": "OPENAI_API_KEY" } if none
| PARAMETER | DESCRIPTION |
|---|---|
dotenv_file_path |
The path to the .env file. Defaults to None. TYPE: strDEFAULT:None |
model_api_key_map |
A dictionary mapping models to their API key configurations. If a string is provided as configuration, it is considered as an environment variable name storing the API key. If a dict is provided, it should contain at least 'api_key_env_var' key, and optionally other API configurations like 'base_url', 'api_type', and 'api_version'. Defaults to a basic map with 'gpt-4' and 'gpt-3.5-turbo' mapped to 'OPENAI_API_KEY'. TYPE: str / dictDEFAULT:None |
filter_dict |
A dictionary containing the models to be loaded. Containing a 'model' key mapped to a set of model names to be loaded. Defaults to None, which loads all found configurations. TYPE: dictDEFAULT:None |
| RETURNS | DESCRIPTION |
|---|---|
| `list[dict[str, str | set[str]]]` |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError |
If the specified .env file does not exist. |
TypeError |
If an unsupported type of configuration is provided in model_api_key_map. |
Source code in autogen/oai/openai_utils.py
<br>531<br>532<br>533<br>534<br>535<br>536<br>537<br>538<br>539<br>540<br>541<br>542<br>543<br>544<br>545<br>546<br>547<br>548<br>549<br>550<br>551<br>552<br>553<br>554<br>555<br>556<br>557<br>558<br>559<br>560<br>561<br>562<br>563<br>564<br>565<br>566<br>567<br>568<br>569<br>570<br>571<br>572<br>573<br>574<br>575<br>576<br>577<br>578<br>579<br>580<br>581<br>582<br>583<br>584<br>585<br>586<br>587<br>588<br>589<br>590<br>591<br>592<br>593<br>594<br>595<br>596<br>597<br>598<br>599<br>600<br>601<br>602<br>603<br>604<br>605<br>606<br>607<br>608<br>609<br>610<br>611<br>612<br>613<br>614<br>615<br>616<br>617<br>618<br>619<br>620<br>621<br>622<br>623<br>624<br>625<br>626<br>627<br>628<br>629<br>630<br>631<br> |
``` @export_module("autogen") def config_list_from_dotenv( dotenv_file_path: str |