config_list_from_dotenv
autogen.config_list_from_dotenv #
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: |
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'. |
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: |
RETURNS | DESCRIPTION |
---|---|
list[dict[str, Union[str, set[str]]]] | List[Dict[str, Union[str, Set[str]]]]: A list of configuration dictionaries for each model. |
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
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 |
|