Replies: 1 comment
-
To implement Azure AD authentication for embedding models using Here's how you might modify the from azure.identity import DefaultAzureCredential
from typing import Any, Dict, Optional
class AzureOpenAIEmbeddingWithAD(AzureOpenAIEmbedding):
def __init__(self, *args, use_azure_ad: bool = False, **kwargs):
super().__init__(*args, **kwargs)
self.use_azure_ad = use_azure_ad
self.azure_credential = DefaultAzureCredential() if self.use_azure_ad else None
def _get_credential_kwargs(self) -> Dict[str, Any]:
credential_kwargs = super()._get_credential_kwargs()
if self.use_azure_ad:
token = self.azure_credential.get_token("https://cognitiveservices.azure.com/.default").token
credential_kwargs["default_headers"] = {
**credential_kwargs.get("default_headers", {}),
"Authorization": f"Bearer {token}"
}
return credential_kwargs In this example, the This approach allows you to leverage Azure AD authentication for embedding models using Please ensure you have the Azure Identity library installed ( The If you have any other questions or need further assistance, feel free to ask. Sources
|
Beta Was this translation helpful? Give feedback.
-
How should I go about using Entra / Azure AD authentication for embedding models?
For llm (AzureOpenAI), there is a parameter "use_azure_ad" but for embedding (AzureOpenAIEmbedding) there is none.
Beta Was this translation helpful? Give feedback.
All reactions