-
Notifications
You must be signed in to change notification settings - Fork 13.4k
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
AzureOpenAI azure_ad_token_provider Keyerror #14069
Comments
🤖 Hello @axen22! 👋 I'm Dosu, an AI here to assist you with your issue while we wait for a human maintainer. This is my first time interacting with you, and I'm here to help you solve bugs, answer questions, and guide you through the contribution process. Let's get started! Based on the information you've provided and the context from the LangChain repository, it seems like the Here is an example of how you can do this: def my_token_provider():
# Your logic to get a new token from Azure Active Directory
return new_token
azure_chat = AzureChatOpenAI(
azure_deployment="35-turbo-dev",
openai_api_version="2023-05-15",
azure_ad_token_provider=my_token_provider,
) In the above code, replace However, there seems to be a discrepancy in the type hint for I also found a similar solved issue in the LangChain repository: Azure OpenAI token authenticate issue. which suggests setting the OPENAI_API_KEY and OPENAI_API_VERSION as environment variables and using the AzureOpenAI class with the "azure_ad" api_type. Please try the above suggestions and let me know if it helps. If the issue persists, it might be a good idea to raise this as a new issue in the LangChain repository, as it could be a bug or a documentation error. Sources |
Same behaviour from my side. I confirm the issue. |
Change `azure_ad_token_provider` type
@axen22 @clemlesne I've submitted a PR to address this issue. If you are in a hurry, you can use it like this: client = AzureOpenAI(azure_endpoint=endpoint,
api_version="2023-05-15",
azure_deployment="example-gpt-4",
azure_ad_token_provider=token_provider()) |
Change `azure_ad_token_provider` type
Change `azure_ad_token_provider` type
@169 fix will be part of version "0.0.344" ? tested "0.0.344" now, still same issue appears. also tried
I get:
|
@axen22 This PR has not been merged yet. I will mention you after it is merged and published. Sorry, I know, |
### Description Fix langchain-ai#14069 ### Twitter handle [lin_bob57617](https://twitter.com/lin_bob57617)
@axen22 @clemlesne The new version has been released, please upgrade to the latest version |
### Description Fix langchain-ai#14069 ### Twitter handle [lin_bob57617](https://twitter.com/lin_bob57617)
System Info
When I use below snippet of code
I get error :
Ive also tried AzureChatOpenAI , and I get the same error back.
The error is not reproduced when I use openai library AzureOpenAI .
Also on openai the azure_ad_token_provider has type azure_ad_token_provider: 'AzureADTokenProvider | None' = None while in langchain it has type azure_ad_token_provider: Optional[str] = None which also makes me wonder if it would take as input a different type than string to work with.
any ideas on how to fix this? Im actually using Azure Service principal authentication, and if I use as alternative field azure_ad_token = credential.get_token(“https://cognitiveservices.azure.com/.default”).token I get token expired after 60min which does not happen with a bearer token, so It is important to me to make the token_provider work.
libraries :
pydantic 1.10.12
pydantic_core 2.10.1
openai 1.2.0
langchain 0.0.342
langchain-core 0.0.7
Who can help?
@hwchase17 @agola11
Information
Related Components
Reproduction
import os
from azure.identity import DefaultAzureCredential
from azure.identity import get_bearer_token_provider
from langchain.llms import AzureOpenAI
from langchain.chat_models import AzureChatOpenAI
credential = DefaultAzureCredential(interactive_browser_tenant_id=tenant_id,
interactive_browser_client_id=client_id,
client_secret=client_secret)
token_provider = get_bearer_token_provider(credential, "https://cognitiveservices.azure.com/.default")
endpoint = "https://xxxx.openai.azure.com"
client = AzureOpenAI( azure_endpoint=endpoint,
api_version="2023-05-15",
azure_deployment="example-gpt-4",
azure_ad_token_provider=token_provider)
Expected behavior
client = AzureOpenAI( azure_endpoint=endpoint,
api_version="2023-05-15",
azure_deployment="example-gpt-4",
azure_ad_token_provider=token_provider)
should return a Runnable instance which I can use for LLMChain
The text was updated successfully, but these errors were encountered: