# PR Description ## Split toolkits This PR splits the `Microsoft`, `Google`, and `Search` toolkits into multiple toolkits each. * `Microsoft` --> `OutlookCalendar`, `OutlookMail`. * `Google` -----> `GoogleCalendar`, `GoogleContacts`, `GoogleDocs`, `GoogleDrive`, `Gmail`, `GoogleSheets` * `Search` -----> `GoogleFinance`, `GoogleFlights`, `GoogleHotels`, `GoogleJobs`, `GoogleMaps`, `GoogleNews`, `GoogleSearch`, `GoogleShopping`, `Walmart`, `Youtube` > The original monolithic toolkits (`Microsoft`, `Google`, `Search`) are not removed in this PR. The plan is to keep those toolkits around while we > 1. Stop documenting the toolkits, > 2. Stop displaying the toolkits in the dashboard, and > 3. Help customers migrate over to the new split toolkits. ## Rename toolkits This PR renames the following toolkits * `Web` ------------> `Firecrawl` * `CodeSandbox` ---> `E2B` > The `Web` and `CodeSandbox` toolkits are not removed in this PR. The plan is to keep them around while we > 1. Stop documenting the toolkits, > 2. Stop displaying the toolkits in the dashboard, and > 3. Help customers migrate over to the new renamed toolkits. ## Rename tools Since toolkit names were changed, this called for some tools to be renamed as well. * `GoogleSearch.SearchGoogle` ----------------> `GoogleSearch.Search` * `GoogleShopping.SearchShoppingProducts` ---> `GoogleShopping.SearchProducts` * `Walmart.SearchWalmartProducts` ------------> `Walmart.SearchProducts` * `Walmart.GetWalmartProductDetails` ---------> `Walmart.GetProductDetails` * `Youtube.SearchYoutubeVideos` --------------> `Youtube.SearchForVideos` ## Google File Picker Improvements to the Google File Picker experience were also added in this PR. The following tools will ALWAYS provide llm_instructions in their response to "let the end-user know that they have the option to select more files via the file picker url if they want to": * `GoogleDocs.SearchDocuments` * `GoogleDocs.SearchAndRetrieveDocuments` * `GoogleDrive.GetFileTreeStructure` The following tools will only provide the file picker URL if a 404 or 403 from the Google API: * `GoogleDocs.InsertTextAtEndOfDocument` * `GoogleDocs.GetDocumentById` * `GoogleSheets.GetSpreadsheet` * `GoogleSheets.WriteToCell` Also, a standalone `GoogleDrive.GenerateGoogleFilePickerUrl` tool exists. ## Other * The `SearchDocuments` and `SearchAndRetrieveDocuments` tools used to be organized within the Drive portion of the Google toolkit, but I moved these into the new GoogleDocs toolkit because they are specific to Docs. # Progress - [x] `OutlookCalendar` - [x] `OutlookMail` - [x] `GoogleFinance` - [x] `GoogleFlights` - [x] `GoogleHotels` - [x] `GoogleJobs` - [x] `GoogleMaps` - [x] `GoogleNews` - [x] `GoogleSearch` - [x] `GoogleShopping` - [x] `Walmart` - [x] `Youtube` - [x] `GoogleCalendar` - [x] `GoogleContacts` - [x] `GoogleDocs` - [x] `GoogleDrive` - [x] `Gmail` - [x] `GoogleSheets` - [x] `Firecrawl` - [x] `E2B` - [x] File picker # Discussion * Repeated code is a consequence of splitting toolkits that use the same provider. I am open to any ideas that would allow multiple toolkits to reference common code. Comment your ideas in this PR.
74 lines
2.7 KiB
Python
74 lines
2.7 KiB
Python
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
from arcade_tdk import ToolContext, ToolSecretItem
|
|
from arcade_tdk.errors import ToolExecutionError
|
|
|
|
from arcade_e2b.enums import E2BSupportedLanguage
|
|
from arcade_e2b.tools.create_chart import create_static_matplotlib_chart
|
|
from arcade_e2b.tools.run_code import run_code
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_run_code_sandbox():
|
|
with patch("arcade_e2b.tools.run_code.Sandbox") as mock:
|
|
yield mock.return_value.__enter__.return_value
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_create_chart_sandbox():
|
|
with patch("arcade_e2b.tools.create_chart.Sandbox") as mock:
|
|
yield mock.return_value.__enter__.return_value
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_context():
|
|
return ToolContext(secrets=[ToolSecretItem(key="e2b_api_key", value="fake_api_key")])
|
|
|
|
|
|
def test_run_code_success(mock_run_code_sandbox, mock_context):
|
|
mock_execution = MagicMock()
|
|
mock_execution.to_json.return_value = '{"result": "success"}'
|
|
mock_run_code_sandbox.run_code.return_value = mock_execution
|
|
|
|
result = run_code(mock_context, "print('Hello, World!')", E2BSupportedLanguage.PYTHON)
|
|
assert result == '{"result": "success"}'
|
|
|
|
|
|
def test_run_code_error(mock_run_code_sandbox, mock_context):
|
|
mock_execution = MagicMock()
|
|
mock_execution.to_json.side_effect = ToolExecutionError("Execution failed")
|
|
mock_run_code_sandbox.run_code.return_value = mock_execution
|
|
|
|
with pytest.raises(ToolExecutionError, match="Execution failed"):
|
|
run_code(mock_context, "print('Hello, World!')", E2BSupportedLanguage.PYTHON)
|
|
|
|
|
|
def test_create_static_matplotlib_chart_success(mock_create_chart_sandbox, mock_context):
|
|
mock_execution = MagicMock()
|
|
mock_execution.results = [MagicMock(png="base64encodedimage")]
|
|
mock_execution.logs.to_json.return_value = '{"logs": "log data"}'
|
|
mock_execution.error = None
|
|
mock_create_chart_sandbox.run_code.return_value = mock_execution
|
|
|
|
result = create_static_matplotlib_chart(mock_context, "import matplotlib.pyplot as plt")
|
|
assert result == {
|
|
"base64_image": "base64encodedimage",
|
|
"logs": '{"logs": "log data"}',
|
|
"error": None,
|
|
}
|
|
|
|
|
|
def test_create_static_matplotlib_chart_error(mock_create_chart_sandbox, mock_context):
|
|
mock_execution = MagicMock()
|
|
mock_execution.results = []
|
|
mock_execution.logs.to_json.return_value = '{"logs": "log data"}'
|
|
mock_execution.error.to_json.return_value = '{"error": "some error"}'
|
|
mock_create_chart_sandbox.run_code.return_value = mock_execution
|
|
|
|
result = create_static_matplotlib_chart(mock_context, "import matplotlib.pyplot as plt")
|
|
assert result == {
|
|
"base64_image": None,
|
|
"logs": '{"logs": "log data"}',
|
|
"error": '{"error": "some error"}',
|
|
}
|