Python: Removed DefaultAzureCredential (#490)

* Removed DefaultAzureCredential

* Renamed ad_credential to credential
This commit is contained in:
Dmytro Struk
2025-08-26 08:33:17 -07:00
committed by GitHub
Unverified
parent 20d861076a
commit fa88641263
36 changed files with 230 additions and 148 deletions
@@ -120,7 +120,7 @@ class FoundryChatClient(ChatClientBase):
thread_id: str | None = None,
project_endpoint: str | None = None,
model_deployment_name: str | None = None,
async_ad_credential: AsyncTokenCredential | None = None,
async_credential: AsyncTokenCredential | None = None,
env_file_path: str | None = None,
env_file_encoding: str | None = None,
**kwargs: Any,
@@ -137,7 +137,7 @@ class FoundryChatClient(ChatClientBase):
conversation_id property, when making a request.
project_endpoint: The Azure AI Foundry project endpoint URL. Used if client is not provided.
model_deployment_name: The model deployment name to use for agent creation.
async_ad_credential: Azure async credential to use for authentication.
async_credential: Azure async credential to use for authentication.
env_file_path: Path to environment file for loading settings.
env_file_encoding: Encoding of the environment file.
**kwargs: Additional keyword arguments passed to the parent class.
@@ -162,15 +162,15 @@ class FoundryChatClient(ChatClientBase):
if agent_id is None and not foundry_settings.model_deployment_name:
raise ServiceInitializationError("Model deployment name is required for agent creation.")
# Use provided credential or fallback to DefaultAzureCredential
if not async_ad_credential:
# Use provided credential
if not async_credential:
raise ServiceInitializationError("Azure AD credential is required when client is not provided.")
client = AIProjectClient(endpoint=foundry_settings.project_endpoint, credential=async_ad_credential)
client = AIProjectClient(endpoint=foundry_settings.project_endpoint, credential=async_credential)
should_close_client = True
super().__init__(
client=client, # type: ignore[reportCallIssue]
credential=async_ad_credential, # type: ignore[reportCallIssue]
credential=async_credential, # type: ignore[reportCallIssue]
agent_id=agent_id, # type: ignore[reportCallIssue]
thread_id=thread_id, # type: ignore[reportCallIssue]
agent_name=foundry_settings.agent_name, # type: ignore[reportCallIssue]
@@ -24,7 +24,7 @@ from azure.ai.agents.models import (
ThreadRun,
)
from azure.core.credentials_async import AsyncTokenCredential
from azure.identity.aio import DefaultAzureCredential
from azure.identity.aio import AzureCliCredential
from pydantic import Field, ValidationError
from agent_framework_foundry import FoundryChatClient, FoundrySettings
@@ -133,7 +133,7 @@ def test_foundry_chat_client_init_missing_project_endpoint() -> None:
agent_id=None,
project_endpoint=None, # Missing endpoint
model_deployment_name="test-model",
async_ad_credential=AsyncMock(spec=AsyncTokenCredential),
async_credential=AsyncMock(spec=AsyncTokenCredential),
)
@@ -153,7 +153,7 @@ def test_foundry_chat_client_init_missing_model_deployment_for_agent_creation()
agent_id=None, # No existing agent
project_endpoint="https://test.com",
model_deployment_name=None, # Missing for agent creation
async_ad_credential=AsyncMock(spec=AsyncTokenCredential),
async_credential=AsyncMock(spec=AsyncTokenCredential),
)
@@ -187,14 +187,14 @@ def test_foundry_chat_client_from_dict(mock_ai_project_client: MagicMock) -> Non
def test_foundry_chat_client_init_missing_credential(foundry_unit_test_env: dict[str, str]) -> None:
"""Test FoundryChatClient.__init__ when async_ad_credential is missing and no client provided."""
"""Test FoundryChatClient.__init__ when async_credential is missing and no client provided."""
with pytest.raises(ServiceInitializationError, match="Azure AD credential is required when client is not provided"):
FoundryChatClient(
client=None,
agent_id="existing-agent",
project_endpoint=foundry_unit_test_env["FOUNDRY_PROJECT_ENDPOINT"],
model_deployment_name=foundry_unit_test_env["FOUNDRY_MODEL_DEPLOYMENT_NAME"],
async_ad_credential=None, # Missing credential
async_credential=None, # Missing credential
)
@@ -208,7 +208,7 @@ def test_foundry_chat_client_init_validation_error(mock_azure_credential: MagicM
FoundryChatClient(
project_endpoint="https://test.com",
model_deployment_name="test-model",
async_ad_credential=mock_azure_credential,
async_credential=mock_azure_credential,
)
@@ -662,7 +662,7 @@ def get_weather(
@skip_if_foundry_integration_tests_disabled
async def test_foundry_chat_client_get_response() -> None:
"""Test Foundry Chat Client response."""
async with FoundryChatClient(async_ad_credential=DefaultAzureCredential()) as foundry_chat_client:
async with FoundryChatClient(async_credential=AzureCliCredential()) as foundry_chat_client:
assert isinstance(foundry_chat_client, ChatClient)
messages: list[ChatMessage] = []
@@ -686,7 +686,7 @@ async def test_foundry_chat_client_get_response() -> None:
@skip_if_foundry_integration_tests_disabled
async def test_foundry_chat_client_get_response_tools() -> None:
"""Test Foundry Chat Client response with tools."""
async with FoundryChatClient(async_ad_credential=DefaultAzureCredential()) as foundry_chat_client:
async with FoundryChatClient(async_credential=AzureCliCredential()) as foundry_chat_client:
assert isinstance(foundry_chat_client, ChatClient)
messages: list[ChatMessage] = []
@@ -707,7 +707,7 @@ async def test_foundry_chat_client_get_response_tools() -> None:
@skip_if_foundry_integration_tests_disabled
async def test_foundry_chat_client_streaming() -> None:
"""Test Foundry Chat Client streaming response."""
async with FoundryChatClient(async_ad_credential=DefaultAzureCredential()) as foundry_chat_client:
async with FoundryChatClient(async_credential=AzureCliCredential()) as foundry_chat_client:
assert isinstance(foundry_chat_client, ChatClient)
messages: list[ChatMessage] = []
@@ -737,7 +737,7 @@ async def test_foundry_chat_client_streaming() -> None:
@skip_if_foundry_integration_tests_disabled
async def test_foundry_chat_client_streaming_tools() -> None:
"""Test Foundry Chat Client streaming response with tools."""
async with FoundryChatClient(async_ad_credential=DefaultAzureCredential()) as foundry_chat_client:
async with FoundryChatClient(async_credential=AzureCliCredential()) as foundry_chat_client:
assert isinstance(foundry_chat_client, ChatClient)
messages: list[ChatMessage] = []