Skip to content

Consistently return Boolean for delete methods #359

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

Merged
merged 1 commit into from
Sep 25, 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
10 changes: 6 additions & 4 deletions replicate/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,31 +358,33 @@ async def async_update(

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

def delete(self, deployment_owner: str, deployment_name: str) -> None:
def delete(self, deployment_owner: str, deployment_name: str) -> bool:
"""
Delete an existing deployment.

Args:
deployment_owner: The owner of the deployment.
deployment_name: The name of the deployment.
"""
self._client._request(
resp = self._client._request(
"DELETE",
f"/v1/deployments/{deployment_owner}/{deployment_name}",
)
return resp.status_code == 204

async def async_delete(self, deployment_owner: str, deployment_name: str) -> None:
async def async_delete(self, deployment_owner: str, deployment_name: str) -> bool:
"""
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(
resp = await self._client._async_request(
"DELETE",
f"/v1/deployments/{deployment_owner}/{deployment_name}",
)
return resp.status_code == 204

@property
def predictions(self) -> "DeploymentsPredictions":
Expand Down
10 changes: 6 additions & 4 deletions replicate/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,17 @@ async def async_list(self) -> List[File]:
resp = await self._client._async_request("GET", "/v1/files")
return [_json_to_file(obj) for obj in resp.json().get("results", [])]

def delete(self, file_id: str) -> None:
def delete(self, file_id: str) -> bool:
"""Delete an uploaded file by its ID."""

_ = self._client._request("DELETE", f"/v1/files/{file_id}")
resp = self._client._request("DELETE", f"/v1/files/{file_id}")
return resp.status_code == 204

async def async_delete(self, file_id: str) -> None:
async def async_delete(self, file_id: str) -> bool:
"""Delete an uploaded file by its ID asynchronously."""

_ = await self._client._async_request("DELETE", f"/v1/files/{file_id}")
resp = await self._client._async_request("DELETE", f"/v1/files/{file_id}")
return resp.status_code == 204


def _create_file_params(
Expand Down
29 changes: 13 additions & 16 deletions replicate/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,41 +287,38 @@ async def async_get(self, *args, **kwargs) -> Model:
return _json_to_model(self._client, resp.json())

@overload
def delete(self, key: str) -> Model: ...
def delete(self, key: str) -> bool: ...

@overload
def delete(self, owner: str, name: str) -> Model: ...
def delete(self, owner: str, name: str) -> bool: ...

def delete(self, *args, **kwargs) -> Model:
def delete(self, *args, **kwargs) -> bool:
"""
Delete a model by name.
"""

Returns:
`True` if deletion was successful, otherwise `False`.
"""
url = _delete_model_url(*args, **kwargs)
resp = self._client._request("DELETE", url)

return _json_to_model(self._client, resp.json())
return resp.status_code == 204

@overload
async def async_delete(self, key: str) -> Model: ...
async def async_delete(self, key: str) -> bool: ...

@overload
async def async_delete(self, owner: str, name: str) -> Model: ...
async def async_delete(self, owner: str, name: str) -> bool: ...

async def async_delete(self, *args, **kwargs) -> Model:
async def async_delete(self, *args, **kwargs) -> bool:
"""
Delete a model by name.
Asynchronously delete a model by name.

Args:
key: The qualified name of the model, in the format `owner/name`.
Returns:
The model.
`True` if deletion was successful, otherwise `False`.
"""

url = _delete_model_url(*args, **kwargs)
resp = await self._client._async_request("DELETE", url)

return _json_to_model(self._client, resp.json())
return resp.status_code == 204

class CreateModelParams(TypedDict):
"""Parameters for creating a model."""
Expand Down