# config_list_from_models

## `autogen.config_list_from_models`

```
config_list_from_models(key_file_path='.', openai_api_key_file='key_openai.txt', aoai_api_key_file='key_aoai.txt', aoai_api_base_file='base_aoai.txt', exclude=None, model_list=None)
```

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

This function extends `config_list_openai_aoai` by allowing to clone its' out for each of the models provided. Each configuration will have a 'model' key with the model name as its value. This is particularly useful when all endpoints have same set of models.

| PARAMETER                  | DESCRIPTION                                                                                                                                               |
|----------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
| `key_file_path`           | The path to the key files.<br>**TYPE:**`str`**DEFAULT:**`'.'`                                                                                           |
| `openai_api_key_file`     | The file name of the OpenAI API key.<br>**TYPE:**`str`**DEFAULT:**`'key_openai.txt'`                                                                   |
| `aoai_api_key_file`       | The file name of the Azure OpenAI API key.<br>**TYPE:**`str`**DEFAULT:**`'key_aoai.txt'`                                                               |
| `aoai_api_base_file`      | The file name of the Azure OpenAI API base.<br>**TYPE:**`str`**DEFAULT:**`'base_aoai.txt'`                                                             |
| `exclude`                 | The API type to exclude, "openai" or "aoai".<br>**TYPE:**`str`**DEFAULT:**`None`                                                                   |
| `model_list`              | The list of model names to include in the configs.<br>**TYPE:**`list`**DEFAULT:**`None`                                                                  |

| RETURNS                    | DESCRIPTION                                                                                                                                               |
|----------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
| `list`                     | A list of configs for OpenAI API calls, each including model information.<br>**TYPE:**`list[dict[str, Any]]`                                             |

Example:

```
# Define the path where the API key files are located
key_file_path = "/path/to/key/files"

# Define the file names for the OpenAI and Azure OpenAI API keys and bases
openai_api_key_file = "key_openai.txt"
aoai_api_key_file = "key_aoai.txt"
aoai_api_base_file = "base_aoai.txt"

# Define the list of models for which to create configurations
model_list = ["gpt-4", "gpt-3.5-turbo"]

# Call the function to get a list of configuration dictionaries
config_list = config_list_from_models(
    key_file_path=key_file_path,
    openai_api_key_file=openai_api_key_file,
    aoai_api_key_file=aoai_api_key_file,
    aoai_api_base_file=aoai_api_base_file,
    model_list=model_list,
)

# The `config_list` will contain configurations for the specified models, for example:
# [
#     {'api_key': '...', 'base_url': 'https://api.openai.com', 'model': 'gpt-4'},
#     {'api_key': '...', 'base_url': 'https://api.openai.com', 'model': 'gpt-3.5-turbo'}
# ]
```

Source code in `autogen/oai/openai_utils.py`

|     |     |
| --- | --- |
| ```<br>349<br>350<br>351<br>352<br>353<br>354<br>355<br>356<br>357<br>358<br>359<br>360<br>361<br>362<br>363<br>364<br>365<br>366<br>367<br>368<br>369<br>370<br>371<br>372<br>373<br>374<br>375<br>376<br>377<br>378<br>379<br>380<br>381<br>382<br>383<br>384<br>385<br>386<br>387<br>388<br>389<br>390<br>391<br>392<br>393<br>394<br>395<br>396<br>397<br>398<br>399<br>400<br>401<br>402<br>403<br>404<br>405<br>406<br>407<br>408<br>409<br>410<br>411<br>412<br>413<br>``` | ````<br>@export_module("autogen")<br>def config_list_from_models(<br>    key_file_path: Optional[str] = ".",<br>    openai_api_key_file: Optional[str] = "key_openai.txt",<br>    aoai_api_key_file: Optional[str] = "key_aoai.txt",<br>    aoai_api_base_file: Optional[str] = "base_aoai.txt",<br>    exclude: Optional[str] = None,<br>    model_list: Optional[list[str]] = None,<br>) -> list[dict[str, Any]]:<br>    """Get a list of configs for API calls with models specified in the model list.<br>    This function extends `config_list_openai_aoai` by allowing to clone its' out for each of the models provided.<br>    Each configuration will have a 'model' key with the model name as its value. This is particularly useful when<br>    all endpoints have same set of models.<br>    Args:<br>        key_file_path (str, optional): The path to the key files.<br>        openai_api_key_file (str, optional): The file name of the OpenAI API key.<br>        aoai_api_key_file (str, optional): The file name of the Azure OpenAI API key.<br>        aoai_api_base_file (str, optional): The file name of the Azure OpenAI API base.<br>        exclude (str, optional): The API type to exclude, "openai" or "aoai".<br>        model_list (list, optional): The list of model names to include in the configs.<br>    Returns:<br>        list: A list of configs for OpenAI API calls, each including model information.<br>    Example:<br>    ```python<br>    # Define the path where the API key files are located<br>    key_file_path = "/path/to/key/files"<br>    # Define the file names for the OpenAI and Azure OpenAI API keys and bases<br>    openai_api_key_file = "key_openai.txt"<br>    aoai_api_key_file = "key_aoai.txt"<br>    aoai_api_base_file = "base_aoai.txt"<br>    # Define the list of models for which to create configurations<br>    model_list = ["gpt-4", "gpt-3.5-turbo"]<br>    # Call the function to get a list of configuration dictionaries<br>    config_list = config_list_from_models(<br>        key_file_path=key_file_path,<br>        openai_api_key_file=openai_api_key_file,<br>        aoai_api_key_file=aoai_api_key_file,<br>        aoai_api_base_file=aoai_api_base_file,<br>        model_list=model_list,<br>    )<br>    # The `config_list` will contain configurations for the specified models, for example:<br>    # [<br>    #     {'api_key': '...', 'base_url': 'https://api.openai.com', 'model': 'gpt-4'},<br>    #     {'api_key': '...', 'base_url': 'https://api.openai.com', 'model': 'gpt-3.5-turbo'}<br>    # ]<br>    ```<br>    """<br>    config_list = config_list_openai_aoai(<br>        key_file_path=key_file_path,<br>        openai_api_key_file=openai_api_key_file,<br>        aoai_api_key_file=aoai_api_key_file,<br>        aoai_api_base_file=aoai_api_base_file,<br>        exclude=exclude,<br>    )<br>    if model_list:<br>        config_list = [{**config, "model": model} for model in model_list for config in config_list]<br>    return config_list<br>```` |
