Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate GriptapeCloudStructureRunDriver to use env_var over env field #1118

Merged
merged 2 commits into from
Aug 29, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ def try_run(self, *args: BaseArtifact) -> BaseArtifact | InfoArtifact:

url = urljoin(self.base_url.strip("/"), f"/api/structures/{self.structure_id}/runs")

env_vars = [{"name": key, "value": value, "source": "manual"} for key, value in self.env.items()]

response: Response = post(
url,
json={"args": [arg.value for arg in args], "env": self.env},
json={"args": [arg.value for arg in args], "env_vars": env_vars},
headers=self.headers,
)
response.raise_for_status()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@

class TestGriptapeCloudStructureRunDriver:
@pytest.fixture()
def driver(self, mocker):
from griptape.drivers import GriptapeCloudStructureRunDriver

def mock_requests_post(self, mocker):
mock_response = mocker.Mock()
mock_response.json.return_value = {"structure_run_id": 1}
mocker.patch("requests.post", return_value=mock_response)
return mocker.patch("requests.post", return_value=mock_response)

@pytest.fixture()
def driver(self, mocker, mock_requests_post):
from griptape.drivers import GriptapeCloudStructureRunDriver

mock_response = mocker.Mock()
mock_response.json.return_value = {
Expand All @@ -24,10 +26,15 @@ def driver(self, mocker):
base_url="https://cloud-foo.griptape.ai", api_key="foo bar", structure_id="1", env={"key": "value"}
)

def test_run(self, driver):
def test_run(self, driver, mock_requests_post):
result = driver.run(TextArtifact("foo bar"))
assert isinstance(result, TextArtifact)
assert result.value == "foo bar"
mock_requests_post.assert_called_once_with(
"https://cloud-foo.griptape.ai/api/structures/1/runs",
json={"args": ["foo bar"], "env_vars": [{"name": "key", "value": "value", "source": "manual"}]},
headers={"Authorization": "Bearer foo bar"},
)

def test_async_run(self, driver):
driver.async_run = True
Expand Down
Loading