config_list_from_models - AG2
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. TYPE: strDEFAULT:'.' |
openai_api_key_file |
The file name of the OpenAI API key. TYPE: strDEFAULT:'key_openai.txt' |
aoai_api_key_file |
The file name of the Azure OpenAI API key. TYPE: strDEFAULT:'key_aoai.txt' |
aoai_api_base_file |
The file name of the Azure OpenAI API base. TYPE: strDEFAULT:'base_aoai.txt' |
exclude |
The API type to exclude, "openai" or "aoai". TYPE: strDEFAULT:None |
model_list |
The list of model names to include in the configs. TYPE: listDEFAULT:None |
| RETURNS | DESCRIPTION |
|---|---|
list |
A list of configs for OpenAI API calls, each including model information. 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" # pragma: allowlist secret
aoai_api_key_file = "key_aoai.txt" # pragma: allowlist secret
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_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>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>414<br>415<br>416<br>417<br>418<br>419<br>420<br>421<br>422<br>423<br>424<br>425<br>426<br>427<br>428<br>429<br>430<br>431<br>432<br>433<br>434<br>435<br>436<br>437<br>438<br>439<br>440<br>441<br>442<br>443<br>444<br>445<br>446<br>447<br>448<br>449<br>450<br>451<br>452<br>453<br>454<br>455<br>456<br>457<br>458<br>459<br>460<br> |
``` @export_module("autogen") def config_list_from_models( key_file_path: str |