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
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 |
|