-
Checked other resources
Commit to Help
Example CodeNo code for now DescriptionI'm trying to use AzureOpenAIEmbeddings class for an internal (work) application. We have a Azure Private endpoint enabled for ada-002 model. The authentication is based on service principles. A good example on how Auth would work for the openai chat completion API is shown here https://github.com/LazaUK/AOAI-EntraIDAuth-SDKv1?tab=readme-ov-file#scenario-3-authenticating-with-entra-id---service-principal. The problem I am facing is since AzureOpenAIEmbeddings does not accept Entra-id based authentication for the underlying openai client but expects a OPENAI_API_KEY key to be provided. Is there a workaround for this? System InfoNot a bug, so not helpful. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
🤖 Hey @thusithaC, back at it with another interesting challenge, I see! Good to have you around. Based on the LangChain codebase, it appears that the AzureOpenAIEmbeddings class does support Azure AD token-based authentication. This can be done either directly using the Here's an example of how you can use the from langchain_openai import AzureOpenAIEmbeddings
def my_token_provider():
# Your logic to get the Azure AD token
return "your_azure_ad_token"
openai = AzureOpenAIEmbeddings(
model="text-embedding-3-large",
azure_ad_token_provider=my_token_provider
) In this example, Alternatively, if you want to use the from langchain_openai import AzureOpenAIEmbeddings
openai = AzureOpenAIEmbeddings(
model="text-embedding-3-large",
azure_ad_token="your_azure_ad_token"
) In this case, you need to make sure that your token is valid for the duration of your application, as it won't be refreshed automatically. You can find more details in the AzureOpenAIEmbeddings class definition. Please let me know if this helps or if you need further assistance. SourcesThis response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
-
does anyone here know if i can use aad auth on azureChatOpenAi class? I have the same scenario |
Beta Was this translation helpful? Give feedback.
🤖
Hey @thusithaC, back at it with another interesting challenge, I see! Good to have you around.
Based on the LangChain codebase, it appears that the AzureOpenAIEmbeddings class does support Azure AD token-based authentication. This can be done either directly using the
azure_ad_token
field or via a function provided to theazure_ad_token_provider
field.Here's an example of how you can use the
azure_ad_token_provider
field: