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: |
openai_api_key_file | The filename containing the OpenAI API key. Defaults to 'key_openai.txt'. TYPE: |
aoai_api_key_file | The filename containing the Azure OpenAI API key. Defaults to 'key_aoai.txt'. TYPE: |
openai_api_base_file | The filename containing the OpenAI API base URL. Defaults to 'base_openai.txt'. TYPE: |
aoai_api_base_file | The filename containing the Azure OpenAI API base URL. Defaults to 'base_aoai.txt'. TYPE: |
exclude | The API type to exclude from the configuration list. Can be 'openai' or 'aoai'. Defaults to None. TYPE: |
RETURNS | DESCRIPTION |
---|---|
list[dict[str, Any]] | List[Dict]: 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
- key_aoai.txt
- base_aoai.txt
Notes
- The function checks for API keys and base URLs in the following environment variables: 'OPENAI_API_KEY', 'AZURE_OPENAI_API_KEY', 'OPENAI_API_BASE' and 'AZURE_OPENAI_API_BASE'. If these are not found, it attempts to read from the specified files in the 'key_file_path' directory.
- The API version for Azure configurations is set to DEFAULT_AZURE_API_VERSION by default.
- If 'exclude' is set to 'openai', only Azure OpenAI configurations are returned, and vice versa.
- The function assumes that the API keys and base URLs in the environment variables are separated by new lines if there are multiple entries.
Source code in autogen/oai/openai_utils.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
|