Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions python/packages/core/tests/openai/test_openai_assistants_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
ChatMessage,
ChatResponse,
ChatResponseUpdate,
CodeInterpreterToolCallContent,
FunctionCallContent,
FunctionResultContent,
HostedCodeInterpreterTool,
HostedFileSearchTool,
HostedVectorStoreContent,
MCPServerToolCallContent,
Role,
TextContent,
UriContent,
Expand Down Expand Up @@ -614,6 +616,81 @@ def test_parse_function_calls_from_assistants_basic(mock_async_openai: MagicMock
assert contents[0].arguments == {"location": "Seattle"}


def test_parse_run_step_with_code_interpreter_tool_call(mock_async_openai: MagicMock) -> None:
"""Test _parse_run_step_tool_call with code_interpreter type creates CodeInterpreterToolCallContent."""
client = create_test_openai_assistants_client(
mock_async_openai,
model_id="test-model",
assistant_id="test-assistant",
)

# Mock a run with required_action containing code_interpreter tool call
mock_run = MagicMock()
mock_run.id = "run_123"
mock_run.status = "requires_action"

mock_tool_call = MagicMock()
mock_tool_call.id = "call_code_123"
mock_tool_call.type = "code_interpreter"
mock_code_interpreter = MagicMock()
mock_code_interpreter.input = "print('Hello, World!')"
mock_tool_call.code_interpreter = mock_code_interpreter

mock_required_action = MagicMock()
mock_required_action.submit_tool_outputs = MagicMock()
mock_required_action.submit_tool_outputs.tool_calls = [mock_tool_call]
mock_run.required_action = mock_required_action

# Parse the run step
contents = client._parse_function_calls_from_assistants(mock_run, "response_123")

# Should have CodeInterpreterToolCallContent
assert len(contents) == 1
assert isinstance(contents[0], CodeInterpreterToolCallContent)
assert contents[0].call_id == '["response_123", "call_code_123"]'
assert contents[0].inputs is not None
assert len(contents[0].inputs) == 1
assert isinstance(contents[0].inputs[0], TextContent)
assert contents[0].inputs[0].text == "print('Hello, World!')"


def test_parse_run_step_with_mcp_tool_call(mock_async_openai: MagicMock) -> None:
"""Test _parse_run_step_tool_call with mcp type creates MCPServerToolCallContent."""
client = create_test_openai_assistants_client(
mock_async_openai,
model_id="test-model",
assistant_id="test-assistant",
)

# Mock a run with required_action containing mcp tool call
mock_run = MagicMock()
mock_run.id = "run_456"
mock_run.status = "requires_action"

mock_tool_call = MagicMock()
mock_tool_call.id = "call_mcp_456"
mock_tool_call.type = "mcp"
mock_tool_call.name = "fetch_data"
mock_tool_call.server_label = "DataServer"
mock_tool_call.args = {"key": "value"}

mock_required_action = MagicMock()
mock_required_action.submit_tool_outputs = MagicMock()
mock_required_action.submit_tool_outputs.tool_calls = [mock_tool_call]
mock_run.required_action = mock_required_action

# Parse the run step
contents = client._parse_function_calls_from_assistants(mock_run, "response_456")

# Should have MCPServerToolCallContent
assert len(contents) == 1
assert isinstance(contents[0], MCPServerToolCallContent)
assert contents[0].call_id == '["response_456", "call_mcp_456"]'
assert contents[0].tool_name == "fetch_data"
assert contents[0].server_name == "DataServer"
assert contents[0].arguments == {"key": "value"}


def test_prepare_options_basic(mock_async_openai: MagicMock) -> None:
"""Test _prepare_options with basic chat options."""
chat_client = create_test_openai_assistants_client(mock_async_openai)
Expand Down
Loading
Loading