mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: Removed DefaultAzureCredential (#490)
* Removed DefaultAzureCredential * Renamed ad_credential to credential
This commit is contained in:
@@ -13,7 +13,7 @@ from agent_framework import (
|
||||
TextContent,
|
||||
)
|
||||
from agent_framework.exceptions import ServiceInitializationError
|
||||
from azure.identity import DefaultAzureCredential
|
||||
from azure.identity import AzureCliCredential
|
||||
from pydantic import Field
|
||||
|
||||
from agent_framework_azure import AzureAssistantsClient
|
||||
@@ -260,7 +260,7 @@ def get_weather(
|
||||
@skip_if_azure_integration_tests_disabled
|
||||
async def test_azure_assistants_client_get_response() -> None:
|
||||
"""Test Azure Assistants Client response."""
|
||||
async with AzureAssistantsClient(ad_credential=DefaultAzureCredential()) as azure_assistants_client:
|
||||
async with AzureAssistantsClient(credential=AzureCliCredential()) as azure_assistants_client:
|
||||
assert isinstance(azure_assistants_client, ChatClient)
|
||||
|
||||
messages: list[ChatMessage] = []
|
||||
@@ -284,7 +284,7 @@ async def test_azure_assistants_client_get_response() -> None:
|
||||
@skip_if_azure_integration_tests_disabled
|
||||
async def test_azure_assistants_client_get_response_tools() -> None:
|
||||
"""Test Azure Assistants Client response with tools."""
|
||||
async with AzureAssistantsClient(ad_credential=DefaultAzureCredential()) as azure_assistants_client:
|
||||
async with AzureAssistantsClient(credential=AzureCliCredential()) as azure_assistants_client:
|
||||
assert isinstance(azure_assistants_client, ChatClient)
|
||||
|
||||
messages: list[ChatMessage] = []
|
||||
@@ -305,7 +305,7 @@ async def test_azure_assistants_client_get_response_tools() -> None:
|
||||
@skip_if_azure_integration_tests_disabled
|
||||
async def test_azure_assistants_client_streaming() -> None:
|
||||
"""Test Azure Assistants Client streaming response."""
|
||||
async with AzureAssistantsClient(ad_credential=DefaultAzureCredential()) as azure_assistants_client:
|
||||
async with AzureAssistantsClient(credential=AzureCliCredential()) as azure_assistants_client:
|
||||
assert isinstance(azure_assistants_client, ChatClient)
|
||||
|
||||
messages: list[ChatMessage] = []
|
||||
@@ -335,7 +335,7 @@ async def test_azure_assistants_client_streaming() -> None:
|
||||
@skip_if_azure_integration_tests_disabled
|
||||
async def test_azure_assistants_client_streaming_tools() -> None:
|
||||
"""Test Azure Assistants Client streaming response with tools."""
|
||||
async with AzureAssistantsClient(ad_credential=DefaultAzureCredential()) as azure_assistants_client:
|
||||
async with AzureAssistantsClient(credential=AzureCliCredential()) as azure_assistants_client:
|
||||
assert isinstance(azure_assistants_client, ChatClient)
|
||||
|
||||
messages: list[ChatMessage] = []
|
||||
@@ -362,7 +362,7 @@ async def test_azure_assistants_client_streaming_tools() -> None:
|
||||
async def test_azure_assistants_client_with_existing_assistant() -> None:
|
||||
"""Test Azure Assistants Client with existing assistant ID."""
|
||||
# First create an assistant to use in the test
|
||||
async with AzureAssistantsClient(ad_credential=DefaultAzureCredential()) as temp_client:
|
||||
async with AzureAssistantsClient(credential=AzureCliCredential()) as temp_client:
|
||||
# Get the assistant ID by triggering assistant creation
|
||||
messages = [ChatMessage(role="user", text="Hello")]
|
||||
await temp_client.get_response(messages=messages)
|
||||
@@ -370,7 +370,7 @@ async def test_azure_assistants_client_with_existing_assistant() -> None:
|
||||
|
||||
# Now test using the existing assistant
|
||||
async with AzureAssistantsClient(
|
||||
assistant_id=assistant_id, ad_credential=DefaultAzureCredential()
|
||||
assistant_id=assistant_id, credential=AzureCliCredential()
|
||||
) as azure_assistants_client:
|
||||
assert isinstance(azure_assistants_client, ChatClient)
|
||||
assert azure_assistants_client.assistant_id == assistant_id
|
||||
@@ -386,7 +386,7 @@ async def test_azure_assistants_client_with_existing_assistant() -> None:
|
||||
|
||||
|
||||
def test_azure_assistants_client_entra_id_authentication() -> None:
|
||||
"""Test Entra ID authentication path with ad_credential."""
|
||||
"""Test Entra ID authentication path with credential."""
|
||||
mock_credential = MagicMock()
|
||||
|
||||
with (
|
||||
@@ -408,7 +408,7 @@ def test_azure_assistants_client_entra_id_authentication() -> None:
|
||||
deployment_name="test-deployment",
|
||||
api_key="placeholder-key",
|
||||
endpoint="https://test-endpoint.openai.azure.com",
|
||||
ad_credential=mock_credential,
|
||||
credential=mock_credential,
|
||||
token_endpoint="https://login.microsoftonline.com/test",
|
||||
)
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ from agent_framework.openai import (
|
||||
OpenAIContentFilterException,
|
||||
)
|
||||
from agent_framework.telemetry import USER_AGENT_KEY
|
||||
from azure.identity import DefaultAzureCredential
|
||||
from azure.identity import AzureCliCredential
|
||||
from httpx import Request, Response
|
||||
from openai import AsyncAzureOpenAI, AsyncStream
|
||||
from openai.resources.chat.completions import AsyncCompletions as AsyncChatCompletions
|
||||
@@ -601,7 +601,7 @@ def get_story_text() -> str:
|
||||
@skip_if_azure_integration_tests_disabled
|
||||
async def test_azure_openai_chat_client_response() -> None:
|
||||
"""Test Azure OpenAI chat completion responses."""
|
||||
azure_chat_client = AzureChatClient(ad_credential=DefaultAzureCredential())
|
||||
azure_chat_client = AzureChatClient(credential=AzureCliCredential())
|
||||
assert isinstance(azure_chat_client, ChatClient)
|
||||
|
||||
messages: list[ChatMessage] = []
|
||||
@@ -627,7 +627,7 @@ async def test_azure_openai_chat_client_response() -> None:
|
||||
@skip_if_azure_integration_tests_disabled
|
||||
async def test_azure_openai_chat_client_response_tools() -> None:
|
||||
"""Test AzureOpenAI chat completion responses."""
|
||||
azure_chat_client = AzureChatClient(ad_credential=DefaultAzureCredential())
|
||||
azure_chat_client = AzureChatClient(credential=AzureCliCredential())
|
||||
assert isinstance(azure_chat_client, ChatClient)
|
||||
|
||||
messages: list[ChatMessage] = []
|
||||
@@ -648,7 +648,7 @@ async def test_azure_openai_chat_client_response_tools() -> None:
|
||||
@skip_if_azure_integration_tests_disabled
|
||||
async def test_azure_openai_chat_client_streaming() -> None:
|
||||
"""Test Azure OpenAI chat completion responses."""
|
||||
azure_chat_client = AzureChatClient(ad_credential=DefaultAzureCredential())
|
||||
azure_chat_client = AzureChatClient(credential=AzureCliCredential())
|
||||
assert isinstance(azure_chat_client, ChatClient)
|
||||
|
||||
messages: list[ChatMessage] = []
|
||||
@@ -680,7 +680,7 @@ async def test_azure_openai_chat_client_streaming() -> None:
|
||||
@skip_if_azure_integration_tests_disabled
|
||||
async def test_azure_openai_chat_client_streaming_tools() -> None:
|
||||
"""Test AzureOpenAI chat completion responses."""
|
||||
azure_chat_client = AzureChatClient(ad_credential=DefaultAzureCredential())
|
||||
azure_chat_client = AzureChatClient(credential=AzureCliCredential())
|
||||
assert isinstance(azure_chat_client, ChatClient)
|
||||
|
||||
messages: list[ChatMessage] = []
|
||||
|
||||
@@ -14,7 +14,7 @@ from agent_framework import (
|
||||
)
|
||||
from agent_framework.azure import AzureResponsesClient
|
||||
from agent_framework.exceptions import ServiceInitializationError
|
||||
from azure.identity import DefaultAzureCredential
|
||||
from azure.identity import AzureCliCredential
|
||||
from pydantic import BaseModel
|
||||
|
||||
skip_if_azure_integration_tests_disabled = pytest.mark.skipif(
|
||||
@@ -112,7 +112,7 @@ def test_serialize(azure_openai_unit_test_env: dict[str, str]) -> None:
|
||||
@skip_if_azure_integration_tests_disabled
|
||||
async def test_azure_responses_client_response() -> None:
|
||||
"""Test azure responses client responses."""
|
||||
azure_responses_client = AzureResponsesClient(ad_credential=DefaultAzureCredential())
|
||||
azure_responses_client = AzureResponsesClient(credential=AzureCliCredential())
|
||||
|
||||
assert isinstance(azure_responses_client, ChatClient)
|
||||
|
||||
@@ -155,7 +155,7 @@ async def test_azure_responses_client_response() -> None:
|
||||
@skip_if_azure_integration_tests_disabled
|
||||
async def test_azure_responses_client_response_tools() -> None:
|
||||
"""Test azure responses client tools."""
|
||||
azure_responses_client = AzureResponsesClient(ad_credential=DefaultAzureCredential())
|
||||
azure_responses_client = AzureResponsesClient(credential=AzureCliCredential())
|
||||
|
||||
assert isinstance(azure_responses_client, ChatClient)
|
||||
|
||||
@@ -194,7 +194,7 @@ async def test_azure_responses_client_response_tools() -> None:
|
||||
@skip_if_azure_integration_tests_disabled
|
||||
async def test_azure_responses_client_streaming() -> None:
|
||||
"""Test Azure azure responses client streaming responses."""
|
||||
azure_responses_client = AzureResponsesClient(ad_credential=DefaultAzureCredential())
|
||||
azure_responses_client = AzureResponsesClient(credential=AzureCliCredential())
|
||||
|
||||
assert isinstance(azure_responses_client, ChatClient)
|
||||
|
||||
@@ -244,7 +244,7 @@ async def test_azure_responses_client_streaming() -> None:
|
||||
@skip_if_azure_integration_tests_disabled
|
||||
async def test_azure_responses_client_streaming_tools() -> None:
|
||||
"""Test azure responses client streaming tools."""
|
||||
azure_responses_client = AzureResponsesClient(ad_credential=DefaultAzureCredential())
|
||||
azure_responses_client = AzureResponsesClient(credential=AzureCliCredential())
|
||||
|
||||
assert isinstance(azure_responses_client, ChatClient)
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ from agent_framework_azure._entra_id_authentication import (
|
||||
|
||||
@pytest.fixture
|
||||
def mock_credential() -> MagicMock:
|
||||
"""Mock synchronous ChainedTokenCredential."""
|
||||
"""Mock synchronous TokenCredential."""
|
||||
mock_cred = MagicMock()
|
||||
# Create a mock token object with a .token attribute
|
||||
mock_token = MagicMock()
|
||||
@@ -25,7 +25,7 @@ def mock_credential() -> MagicMock:
|
||||
|
||||
@pytest.fixture
|
||||
def mock_async_credential() -> MagicMock:
|
||||
"""Mock asynchronous ChainedTokenCredential."""
|
||||
"""Mock asynchronous AsyncTokenCredential."""
|
||||
mock_cred = MagicMock()
|
||||
# Create a mock token object with a .token attribute
|
||||
mock_token = MagicMock()
|
||||
|
||||
Reference in New Issue
Block a user