Skip to content

Commit

Permalink
Rename GT Cloud run ID env var (#758)
Browse files Browse the repository at this point in the history
  • Loading branch information
zachgiordano authored Apr 25, 2024
1 parent 670616f commit 30d3e29
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class GriptapeCloudEventListenerDriver(BaseEventListenerDriver):
base_url: The base URL of Griptape Cloud. Defaults to the GT_CLOUD_BASE_URL environment variable.
api_key: The API key to authenticate with Griptape Cloud.
headers: The headers to use when making requests to Griptape Cloud. Defaults to include the Authorization header.
run_id: The ID of the Structure Run to publish events to. Defaults to the GT_CLOUD_RUN_ID environment variable.
structure_run_id: The ID of the Structure Run to publish events to. Defaults to the GT_CLOUD_STRUCTURE_RUN_ID environment variable.
"""

base_url: str = field(
Expand All @@ -28,16 +28,16 @@ class GriptapeCloudEventListenerDriver(BaseEventListenerDriver):
headers: dict = field(
default=Factory(lambda self: {"Authorization": f"Bearer {self.api_key}"}, takes_self=True), kw_only=True
)
run_id: str = field(default=Factory(lambda: os.getenv("GT_CLOUD_RUN_ID")), kw_only=True)
structure_run_id: str = field(default=Factory(lambda: os.getenv("GT_CLOUD_STRUCTURE_RUN_ID")), kw_only=True)

@run_id.validator # pyright: ignore
def validate_run_id(self, _, run_id: str):
if run_id is None:
@structure_run_id.validator # pyright: ignore
def validate_run_id(self, _, structure_run_id: str):
if structure_run_id is None:
raise ValueError(
"run_id must be set either in the constructor or as an environment variable (GT_CLOUD_RUN_ID)."
"structure_run_id must be set either in the constructor or as an environment variable (GT_CLOUD_STRUCTURE_RUN_ID)."
)

def try_publish_event(self, event: BaseEvent) -> None:
url = urljoin(self.base_url.strip("/"), f"/api/structure-runs/{self.run_id}/events")
url = urljoin(self.base_url.strip("/"), f"/api/structure-runs/{self.structure_run_id}/events")

requests.post(url=url, json=event.to_dict(), headers=self.headers)
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ def mock_post(self, mocker):
def driver(self):
os.environ["GT_CLOUD_BASE_URL"] = "https://cloud123.griptape.ai"

return GriptapeCloudEventListenerDriver(api_key="foo bar", run_id="bar baz")
return GriptapeCloudEventListenerDriver(api_key="foo bar", structure_run_id="bar baz")

def test_init(self, driver):
assert driver
assert driver.api_key == "foo bar"
assert driver.run_id == "bar baz"
assert driver.structure_run_id == "bar baz"

def test_try_publish_event(self, mock_post, driver):
event = MockEvent()
Expand All @@ -39,6 +39,6 @@ def test_try_publish_event(self, mock_post, driver):
headers={"Authorization": "Bearer foo bar"},
)

def test_no_run_id(self):
def test_no_structure_run_id(self):
with pytest.raises(ValueError):
GriptapeCloudEventListenerDriver(api_key="foo bar")

0 comments on commit 30d3e29

Please sign in to comment.