Skip to main content

autogen.oai.openai_utils

get_key

def get_key(config)

Get a unique identifier of a configuration.

Arguments:

  • config dict or list - A configuration.

Returns:

  • tuple - A unique identifier which can be used as a key for a dict.

get_config_list

def get_config_list(api_keys: List,
api_bases: Optional[List] = None,
api_type: Optional[str] = None,
api_version: Optional[str] = None) -> List[Dict]

Get a list of configs for openai api calls.

Arguments:

  • api_keys list - The api keys for openai api calls.
  • api_bases list, optional - The api bases for openai api calls.
  • api_type str, optional - The api type for openai api calls.
  • api_version str, optional - The api version for openai api calls.

config_list_openai_aoai

def config_list_openai_aoai(
key_file_path: Optional[str] = ".",
openai_api_key_file: Optional[str] = "key_openai.txt",
aoai_api_key_file: Optional[str] = "key_aoai.txt",
aoai_api_base_file: Optional[str] = "base_aoai.txt",
exclude: Optional[str] = None) -> List[Dict]

Get a list of configs for openai + azure openai api calls.

Arguments:

  • key_file_path str, optional - The path to the key files.
  • openai_api_key_file str, optional - The file name of the openai api key.
  • aoai_api_key_file str, optional - The file name of the azure openai api key.
  • aoai_api_base_file str, optional - The file name of the azure openai api base.
  • exclude str, optional - The api type to exclude, "openai" or "aoai".

Returns:

  • list - A list of configs for openai api calls.

config_list_from_models

def config_list_from_models(
key_file_path: Optional[str] = ".",
openai_api_key_file: Optional[str] = "key_openai.txt",
aoai_api_key_file: Optional[str] = "key_aoai.txt",
aoai_api_base_file: Optional[str] = "base_aoai.txt",
exclude: Optional[str] = None,
model_list: Optional[list] = None) -> List[Dict]

Get a list of configs for api calls with models in the model list.

Arguments:

  • key_file_path str, optional - The path to the key files.
  • openai_api_key_file str, optional - The file name of the openai api key.
  • aoai_api_key_file str, optional - The file name of the azure openai api key.
  • aoai_api_base_file str, optional - The file name of the azure openai api base.
  • exclude str, optional - The api type to exclude, "openai" or "aoai".
  • model_list list, optional - The model list.

Returns:

  • list - A list of configs for openai api calls.

config_list_gpt4_gpt35

def config_list_gpt4_gpt35(
key_file_path: Optional[str] = ".",
openai_api_key_file: Optional[str] = "key_openai.txt",
aoai_api_key_file: Optional[str] = "key_aoai.txt",
aoai_api_base_file: Optional[str] = "base_aoai.txt",
exclude: Optional[str] = None) -> List[Dict]

Get a list of configs for gpt-4 followed by gpt-3.5 api calls.

Arguments:

  • key_file_path str, optional - The path to the key files.
  • openai_api_key_file str, optional - The file name of the openai api key.
  • aoai_api_key_file str, optional - The file name of the azure openai api key.
  • aoai_api_base_file str, optional - The file name of the azure openai api base.
  • exclude str, optional - The api type to exclude, "openai" or "aoai".

Returns:

  • list - A list of configs for openai api calls.

filter_config

def filter_config(config_list, filter_dict)

Filter the config list by provider and model.

Arguments:

  • config_list list - The config list.
  • filter_dict dict, optional - The filter dict with keys corresponding to a field in each config, and values corresponding to lists of acceptable values for each key.

Returns:

  • list - The filtered config list.

config_list_from_json

def config_list_from_json(
env_or_file: str,
file_location: Optional[str] = "",
filter_dict: Optional[Dict[str, Union[List[Union[str, None]],
Set[Union[str, None]]]]] = None
) -> List[Dict]

Get a list of configs from a json parsed from an env variable or a file.

Arguments:

  • env_or_file str - The env variable name or file name.
  • file_location str, optional - The file location.
  • filter_dict dict, optional - The filter dict with keys corresponding to a field in each config, and values corresponding to lists of acceptable values for each key. e.g.,
filter_dict = {
"api_type": ["open_ai", None], # None means a missing key is acceptable
"model": ["gpt-3.5-turbo", "gpt-4"],
}

Returns:

  • list - A list of configs for openai api calls.