config_list_openai_aoai - AG2

config_list_openai_aoai

autogen.config_list_openai_aoai

config_list_openai_aoai(key_file_path='.', openai_api_key_file='key_openai.txt', aoai_api_key_file='key_aoai.txt', openai_api_base_file='base_openai.txt', aoai_api_base_file='base_aoai.txt', exclude=None)

Get a list of configs for OpenAI API client (including Azure or local model deployments that support OpenAI's chat completion API).

This function constructs configurations by reading API keys and base URLs from environment variables or text files. It supports configurations for both OpenAI and Azure OpenAI services, allowing for the exclusion of one or the other. When text files are used, the environment variables will be overwritten. To prevent text files from being used, set the corresponding file name to None. Or set key_file_path to None to disallow reading from text files.

PARAMETER DESCRIPTION
key_file_path The directory path where the API key files are located. Defaults to the current directory.
TYPE:strDEFAULT:'.'
openai_api_key_file The filename containing the OpenAI API key. Defaults to 'key_openai.txt'.
TYPE:strDEFAULT:'key_openai.txt'
aoai_api_key_file The filename containing the Azure OpenAI API key. Defaults to 'key_aoai.txt'.
TYPE:strDEFAULT:'key_aoai.txt'
openai_api_base_file The filename containing the OpenAI API base URL. Defaults to 'base_openai.txt'.
TYPE:strDEFAULT:'base_openai.txt'
aoai_api_base_file The filename containing the Azure OpenAI API base URL. Defaults to 'base_aoai.txt'.
TYPE:strDEFAULT:'base_aoai.txt'
exclude The API type to exclude from the configuration list. Can be 'openai' or 'aoai'. Defaults to None.
TYPE:strDEFAULT:None
RETURNS DESCRIPTION
list[dict[str, Any]] A list of configuration dictionaries. Each dictionary contains keys for 'api_key', and optionally 'base_url', 'api_type', and 'api_version'.
RAISES DESCRIPTION
FileNotFoundError If the specified key files are not found and the corresponding API key is not set in the environment variables.

Example

To generate configurations excluding Azure OpenAI:

configs = config_list_openai_aoai(exclude='aoai')

File samples

aoai-12345abcdef67890ghijklmnopqr
aoai-09876zyxwvuts54321fedcba
https://api.azure.com/v1
https://api.azure2.com/v1

Notes

Source code in autogen/oai/openai_utils.py

@export_module("autogen")
def config_list_openai_aoai(
    key_file_path: str | None = ".",
    openai_api_key_file: str | None = "key_openai.txt",
    aoai_api_key_file: str | None = "key_aoai.txt",
    openai_api_base_file: str | None = "base_openai.txt",
    aoai_api_base_file: str | None = "base_aoai.txt",
    exclude: str | None = None,
) -> list[dict[str, Any]]:
    """Get a list of configs for OpenAI API client (including Azure or local model deployments that support OpenAI's chat completion API).
    This function constructs configurations by reading API keys and base URLs from environment variables or text files.
    It supports configurations for both OpenAI and Azure OpenAI services, allowing for the exclusion of one or the other.
    When text files are used, the environment variables will be overwritten.
    To prevent text files from being used, set the corresponding file name to None.
    Or set key_file_path to None to disallow reading from text files.
    """
    # Function implementation...