mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 18:54:30 +00:00
(Feat) - LiteLLM Use UsernamePasswordCredential
for Azure OpenAI (#7496)
* add get_azure_ad_token_from_username_password * docs azure use username / password for auth * update doc * get_azure_ad_token_from_username_password * test test_get_azure_ad_token_from_username_password
This commit is contained in:
parent
2979b8301c
commit
38bfefa6ef
6 changed files with 131 additions and 8 deletions
|
@ -211,3 +211,40 @@ class TestAzureEmbedding(BaseLLMEmbeddingTest):
|
|||
|
||||
def get_custom_llm_provider(self) -> litellm.LlmProviders:
|
||||
return litellm.LlmProviders.AZURE
|
||||
|
||||
|
||||
@patch("azure.identity.UsernamePasswordCredential")
|
||||
@patch("azure.identity.get_bearer_token_provider")
|
||||
def test_get_azure_ad_token_from_username_password(
|
||||
mock_get_bearer_token_provider, mock_credential
|
||||
):
|
||||
from litellm.llms.azure.common_utils import (
|
||||
get_azure_ad_token_from_username_password,
|
||||
)
|
||||
|
||||
# Test inputs
|
||||
client_id = "test-client-id"
|
||||
username = "test-username"
|
||||
password = "test-password"
|
||||
|
||||
# Mock the token provider function
|
||||
mock_token_provider = lambda: "mock-token"
|
||||
mock_get_bearer_token_provider.return_value = mock_token_provider
|
||||
|
||||
# Call the function
|
||||
result = get_azure_ad_token_from_username_password(
|
||||
client_id=client_id, azure_username=username, azure_password=password
|
||||
)
|
||||
|
||||
# Verify UsernamePasswordCredential was called with correct arguments
|
||||
mock_credential.assert_called_once_with(
|
||||
client_id=client_id, username=username, password=password
|
||||
)
|
||||
|
||||
# Verify get_bearer_token_provider was called
|
||||
mock_get_bearer_token_provider.assert_called_once_with(
|
||||
mock_credential.return_value, "https://cognitiveservices.azure.com/.default"
|
||||
)
|
||||
|
||||
# Verify the result is the mock token provider
|
||||
assert result == mock_token_provider
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue