Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azure open ai llm authorization failure with azure_ad_token_provider #1387

Open
qidianshiwei opened this issue Oct 8, 2024 · 3 comments
Open
Labels
bug Something isn't working

Comments

@qidianshiwei
Copy link

System Info

python3.11.7 with pandasai library

🐛 Describe the bug

hello,

I try to use pandas-ai library with azureopen-ai producing token.

And I found it failed when I use

 llm = AzureOpenAI(
        azure_endpoint='https://resndev-dxp-east-us-nonprod-aoai.openai.azure.com',
        azure_ad_token_provider=get_bearer_token_provider(ClientSecretCredential(
            client_id='client_id',
            client_secret='client_secret',
            tenant_id='tenant_id'
        ), 'https://xxxx.azure.com/.default'),
        api_version='2023-09-01-preview',
        deployment_name='gpt-3.5-turbo'
    )

It will raise an error
Azure OpenAI key is required. Please add an environment variableAZURE_OPENAI_API_KEYorOPENAI_API_KEYor passapi_tokenas a named parameter

But if I use ClientSecretCredential( client_id='client_id', client_secret='client_secret', tenant_id='tenant_id' ) to create an valid token, it works

AzureOpenAI(azure_endpoint='https://XXX.azure.com',
                  api_token=token,
                  api_version='2023-09-01-preview',
                  deployment_name='gpt-35-turbo')
@dosubot dosubot bot added the bug Something isn't working label Oct 8, 2024
Copy link

dosubot bot commented Oct 8, 2024

Hello @qidianshiwei! I'm here to help you with your bug. Let's get this sorted out together.

To resolve the authorization failure with Azure OpenAI when using the pandasai library and azure_ad_token_provider, ensure the following:

  1. API Key Requirement: The error indicates that an API key is required. You need to provide it either through the environment variables AZURE_OPENAI_API_KEY or OPENAI_API_KEY, or by passing api_token directly as a parameter.

  2. Azure AD Token Provider: Ensure that azure_ad_token_provider is correctly implemented and returns a valid token. It should be a callable function that provides the Azure AD token.

  3. Environment Variables: Double-check that all necessary environment variables are set correctly, including AZURE_OPENAI_API_KEY or OPENAI_API_KEY.

By addressing these points, you should be able to resolve the issue. If using ClientSecretCredential directly works, ensure that the token provider function is correctly configured to generate a valid token.

To continue talking to Dosu, mention @dosu.

@qidianshiwei
Copy link
Author

qidianshiwei commented Oct 8, 2024 via email

Copy link

dosubot bot commented Oct 8, 2024

The pandasai library requires an API key for Azure OpenAI authorization, even when using azure_ad_token_provider, because the API key is explicitly checked and required by the library for access [1].

While azure_ad_token_provider can provide a token for authentication, the library's current implementation prioritizes the API key. This is different from how some other libraries might handle Azure AD tokens. If you believe the library should support Azure AD tokens without requiring an API key, it might be worth suggesting this feature to the maintainers.

To continue talking to Dosu, mention @dosu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant