Skip to content

Commit

Permalink
Add support for deployments.delete endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
  • Loading branch information
mattt committed Jul 31, 2024
1 parent b0bbc04 commit 3e7cfc0
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
26 changes: 26 additions & 0 deletions replicate/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,32 @@ async def async_update(

return _json_to_deployment(self._client, resp.json())

def delete(self, deployment_owner: str, deployment_name: str) -> None:
"""
Delete an existing deployment.
Args:
deployment_owner: The owner of the deployment.
deployment_name: The name of the deployment.
"""
self._client._request(
"DELETE",
f"/v1/deployments/{deployment_owner}/{deployment_name}",
)

async def async_delete(self, deployment_owner: str, deployment_name: str) -> None:
"""
Delete an existing deployment asynchronously.
Args:
deployment_owner: The owner of the deployment.
deployment_name: The name of the deployment.
"""
await self._client._async_request(
"DELETE",
f"/v1/deployments/{deployment_owner}/{deployment_name}",
)

@property
def predictions(self) -> "DeploymentsPredictions":
"""
Expand Down
30 changes: 30 additions & 0 deletions tests/test_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@
)
)

router.route(
method="DELETE",
path="/deployments/acme/image-upscaler",
name="deployments.delete",
).mock(return_value=httpx.Response(204))

router.route(host="api.replicate.com").pass_through()

Expand Down Expand Up @@ -399,3 +404,28 @@ async def test_update_deployment(async_flag):
assert updated_deployment.current_release.configuration.hardware == "gpu-v100"
assert updated_deployment.current_release.configuration.min_instances == 2
assert updated_deployment.current_release.configuration.max_instances == 10


@respx.mock
@pytest.mark.asyncio
@pytest.mark.parametrize("async_flag", [True, False])
async def test_delete_deployment(async_flag):
client = Client(
api_token="test-token", transport=httpx.MockTransport(router.handler)
)

if async_flag:
await client.deployments.async_delete(
deployment_owner="acme", deployment_name="image-upscaler"
)
else:
client.deployments.delete(
deployment_owner="acme", deployment_name="image-upscaler"
)

assert router["deployments.delete"].called
assert router["deployments.delete"].calls[0].request.method == "DELETE"
assert (
router["deployments.delete"].calls[0].request.url
== "https://api.replicate.com/v1/deployments/acme/image-upscaler"
)

0 comments on commit 3e7cfc0

Please sign in to comment.