Skip to content

Commit

Permalink
Python: Fix cancelled typo (#9389)
Browse files Browse the repository at this point in the history
### Motivation and Context

An agent terminal status was misspelled: canceled -> cancelled

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

Fixing the spelling.

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
  • Loading branch information
moonbox3 authored Oct 23, 2024
1 parent b62c692 commit ae05f2c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class OpenAIAssistantBase(Agent):

allowed_message_roles: ClassVar[list[str]] = [AuthorRole.USER, AuthorRole.ASSISTANT]
polling_status: ClassVar[list[str]] = ["queued", "in_progress", "cancelling"]
error_message_states: ClassVar[list[str]] = ["failed", "canceled", "expired", "incomplete"]
error_message_states: ClassVar[list[str]] = ["failed", "cancelled", "expired", "incomplete"]

channel_type: ClassVar[type[AgentChannel]] = OpenAIAssistantChannel

Expand Down
45 changes: 44 additions & 1 deletion python/tests/unit/agents/test_open_ai_assistant_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,32 @@ def mock_run_incomplete():
)


@pytest.fixture
def mock_run_cancelled():
return Run(
id="run_id",
status="cancelled",
assistant_id="assistant_id",
created_at=123456789,
instructions="instructions",
model="model",
object="thread.run",
thread_id="thread_id",
tools=[],
required_action=RequiredAction(
type="submit_tool_outputs",
submit_tool_outputs=RequiredActionSubmitToolOutputs(
tool_calls=[
RequiredActionFunctionToolCall(
id="tool_call_id", type="function", function=Function(arguments="{}", name="function_name")
)
]
),
),
parallel_tool_calls=True,
)


@pytest.fixture
def mock_function_call_content():
return FunctionCallContent(id="function_call_id", name="function_name", arguments={})
Expand Down Expand Up @@ -1568,7 +1594,7 @@ async def test_poll_run_status(


@pytest.mark.asyncio
async def test_poll_run_status_incomplete_throws(
async def test_poll_run_status_incomplete(
azure_openai_assistant_agent, mock_run_required_action, mock_run_incomplete, openai_unit_test_env
):
with patch.object(azure_openai_assistant_agent, "client", spec=AsyncAzureOpenAI) as mock_client:
Expand All @@ -1584,6 +1610,23 @@ async def test_poll_run_status_incomplete_throws(
assert run.status in azure_openai_assistant_agent.error_message_states


@pytest.mark.asyncio
async def test_poll_run_status_cancelled(
azure_openai_assistant_agent, mock_run_required_action, mock_run_cancelled, openai_unit_test_env
):
with patch.object(azure_openai_assistant_agent, "client", spec=AsyncAzureOpenAI) as mock_client:
mock_client.beta = MagicMock()
mock_client.beta.assistants = MagicMock()

mock_client.beta.threads.runs.retrieve = AsyncMock(return_value=mock_run_cancelled)

run = await azure_openai_assistant_agent._poll_run_status(
run=mock_run_required_action, thread_id="test_thread_id"
)

assert run.status in azure_openai_assistant_agent.error_message_states


@pytest.mark.asyncio
async def test_poll_run_status_exception_polls_again(
azure_openai_assistant_agent, mock_run_required_action, mock_run_completed, openai_unit_test_env
Expand Down

0 comments on commit ae05f2c

Please sign in to comment.