Python: added inline yaml sample (#2582)

* added inline yaml sample

* fixed some typos and added intro comment

* added description params and pass through to client

* add azure assistants

* fix tests

* observabiltiy mypy fix

* for some reason mypy doesn't accept a subclass

---------

Co-authored-by: Evan Mattson <35585003+moonbox3@users.noreply.github.com>
This commit is contained in:
Eduard van Valkenburg
2025-12-04 02:30:56 +01:00
committed by GitHub
Unverified
parent 42ffe59592
commit d774b64df0
12 changed files with 136 additions and 40 deletions
@@ -86,6 +86,7 @@ def create_test_azure_ai_chat_client(
client.credential = None
client.agent_id = agent_id
client.agent_name = agent_name
client.agent_description = None
client.model_id = azure_ai_settings.model_deployment_name
client.thread_id = thread_id
client.should_cleanup_agent = should_cleanup_agent
@@ -441,34 +442,43 @@ async def test_azure_ai_chat_client_close_client_when_should_close_false(mock_ag
mock_agents_client.close.assert_not_called()
def test_azure_ai_chat_client_update_agent_name_when_current_is_none(mock_agents_client: MagicMock) -> None:
"""Test _update_agent_name updates name when current agent_name is None."""
def test_azure_ai_chat_client_update_agent_name_and_description_when_current_is_none(
mock_agents_client: MagicMock,
) -> None:
"""Test _update_agent_name_and_description updates name when current agent_name is None."""
chat_client = create_test_azure_ai_chat_client(mock_agents_client)
chat_client.agent_name = None # type: ignore
chat_client._update_agent_name("NewAgentName") # type: ignore
chat_client._update_agent_name_and_description("NewAgentName", "description") # type: ignore
assert chat_client.agent_name == "NewAgentName"
assert chat_client.agent_description == "description"
def test_azure_ai_chat_client_update_agent_name_when_current_exists(mock_agents_client: MagicMock) -> None:
"""Test _update_agent_name does not update when current agent_name exists."""
def test_azure_ai_chat_client_update_agent_name_and_description_when_current_exists(
mock_agents_client: MagicMock,
) -> None:
"""Test _update_agent_name_and_description does not update when current agent_name exists."""
chat_client = create_test_azure_ai_chat_client(mock_agents_client)
chat_client.agent_name = "ExistingName" # type: ignore
chat_client.agent_description = "ExistingDescription" # type: ignore
chat_client._update_agent_name("NewAgentName") # type: ignore
chat_client._update_agent_name_and_description("NewAgentName", "description") # type: ignore
assert chat_client.agent_name == "ExistingName"
assert chat_client.agent_description == "ExistingDescription"
def test_azure_ai_chat_client_update_agent_name_with_none_input(mock_agents_client: MagicMock) -> None:
"""Test _update_agent_name with None input."""
def test_azure_ai_chat_client_update_agent_name_and_description_with_none_input(mock_agents_client: MagicMock) -> None:
"""Test _update_agent_name_and_description with None input."""
chat_client = create_test_azure_ai_chat_client(mock_agents_client)
chat_client.agent_name = None # type: ignore
chat_client.agent_description = None # type: ignore
chat_client._update_agent_name(None) # type: ignore
chat_client._update_agent_name_and_description(None, None) # type: ignore
assert chat_client.agent_name is None
assert chat_client.agent_description is None
async def test_azure_ai_chat_client_create_run_options_with_messages(mock_agents_client: MagicMock) -> None:
@@ -84,6 +84,7 @@ def create_test_azure_ai_client(
client.credential = None
client.agent_name = agent_name
client.agent_version = agent_version
client.agent_description = None
client.use_latest_version = use_latest_version
client.model_id = azure_ai_settings.model_deployment_name
client.conversation_id = conversation_id
@@ -397,14 +398,14 @@ async def test_azure_ai_client_initialize_client(mock_project_client: MagicMock)
mock_project_client.get_openai_client.assert_called_once()
def test_azure_ai_client_update_agent_name(mock_project_client: MagicMock) -> None:
"""Test _update_agent_name method."""
def test_azure_ai_client_update_agent_name_and_description(mock_project_client: MagicMock) -> None:
"""Test _update_agent_name_and_description method."""
client = create_test_azure_ai_client(mock_project_client)
# Test updating agent name when current is None
with patch.object(client, "_update_agent_name") as mock_update:
with patch.object(client, "_update_agent_name_and_description") as mock_update:
mock_update.return_value = None
client._update_agent_name("new-agent") # type: ignore
client._update_agent_name_and_description("new-agent") # type: ignore
mock_update.assert_called_once_with("new-agent")
# Test behavior when agent name is updated
@@ -412,9 +413,9 @@ def test_azure_ai_client_update_agent_name(mock_project_client: MagicMock) -> No
client.agent_name = "test-agent" # Manually set for the test
# Test with None input
with patch.object(client, "_update_agent_name") as mock_update:
with patch.object(client, "_update_agent_name_and_description") as mock_update:
mock_update.return_value = None
client._update_agent_name(None) # type: ignore
client._update_agent_name_and_description(None) # type: ignore
mock_update.assert_called_once_with(None)