autogen icon indicating copy to clipboard operation
autogen copied to clipboard

[Bug]: AGS throws error when api_key is configured with os.environ["AZURE_OPENAI_API_KEY"]

Open TheAmazingRoderic opened this issue 1 year ago • 0 comments

Describe the bug

Configuring for Azure OpenAI with the environment variable AZURE_OPENAI_API_KEY throws ValueError

"api_key is not present in llm_config or OPENAI_API_KEY env variable for agent..."

This is due to logic that checks for OPENAI_API_KEY but doesn't include a check for the AZURE_OPENAI_KEY configuration. https://github.com/microsoft/autogen/blob/autogenstudio/samples/apps/autogen-studio/autogenstudio/workflowmanager.py#L239-L242

Completely removing the check block allows support of the AZURE_OPENAI_API_KEY configuration and improves the error message

OpenAIError: Missing credentials. Please pass one of api_key, azure_ad_token, azure_ad_token_provider, or the AZURE_OPENAI_API_KEY or AZURE_OPENAI_AD_TOKEN environment variables.

Steps to reproduce

  1. Set the environment variables for Azure OpenAI:
export AZURE_OPENAI_API_KEY="<key>"
export AZURE_OPENAI_API_BASE="<base>"
export OPENAI_API_VERSION="<version>"
#export DEFAULT_AZURE_API_VERSION="<version>" #See Additional Information:Related Issue
  1. Validate the OAI_CONFIG_LIST doesn't contain any keys.
  2. Fire up the AGS: autogenstudio ui
  3. Create new azure model without entering key/base/version
  4. Test Model
Screenshot 2024-08-07 at 12 04 19 PM

Model Used

gpt-4

Expected Behavior

AGS should allow same azure environmental variable configuration as Autogen.

Screenshots and logs

No response

Additional Information

Related Issue

Using the proper 'DEFAULT_AZURE_API_VERSION' results in error message:

Screenshot 2024-08-07 at 12 02 04 PM

TheAmazingRoderic avatar Aug 07 '24 17:08 TheAmazingRoderic