replicate / replicate-python

Python client for Replicate
https://replicate.com
Apache License 2.0
771 stars 222 forks source link

Error when succesfully deleting model without version #356

Closed detkov closed 2 months ago

detkov commented 2 months ago

I had a model model without a version (it was there, but I deleted it):

>>> model
Model(url='https://replicate.com/xxx/yyy', owner='xxx', name='yyy', description=None, visibility='private', github_url=None, paper_url=None, license_url=None, run_count=75, cover_image_url=None, default_example=None, latest_version=None)

I tried to delete it and got the following error:

>>> replicate.models.delete(owner=model.owner, name=model.name)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ubuntu/.cache/pypoetry/virtualenvs/studio-backend-p27wbUyn-py3.10/lib/python3.10/site-packages/replicate/model.py", line 302, in delete
    return _json_to_model(self._client, resp.json())
  File "/home/ubuntu/.cache/pypoetry/virtualenvs/studio-backend-p27wbUyn-py3.10/lib/python3.10/site-packages/httpx/_models.py", line 756, in json
    return jsonlib.loads(self.text, **kwargs)
  File "/opt/conda/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/opt/conda/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/opt/conda/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

However, when trying to get this model using, another error occurs, which means that the model was indeed deleted:

>>> model = replicate.models.get(owner=model.owner, name=model.name)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ubuntu/.cache/pypoetry/virtualenvs/studio-backend-p27wbUyn-py3.10/lib/python3.10/site-packages/replicate/model.py", line 263, in get
    resp = self._client._request("GET", url)
  File "/home/ubuntu/.cache/pypoetry/virtualenvs/studio-backend-p27wbUyn-py3.10/lib/python3.10/site-packages/replicate/client.py", line 89, in _request
    _raise_for_status(resp)
  File "/home/ubuntu/.cache/pypoetry/virtualenvs/studio-backend-p27wbUyn-py3.10/lib/python3.10/site-packages/replicate/client.py", line 385, in _raise_for_status
    raise ReplicateError.from_response(resp)
replicate.exceptions.ReplicateError: ReplicateError Details:
status: 404
detail: No ModelRedirect matches the given query.

So it seems to me that the problem is somewhere in the replicate.models.delete response decoding.

replicate==0.33.0

mattt commented 2 months ago

Hi @detkov. Thanks for reporting. I believe this is a problem with the API, so I'll work with the team to get this fixed.

mattt commented 2 months ago

Following up — I just opened https://github.com/replicate/replicate-python/pull/359 to fix what we can on the client. I also filed a ticket internally to get the API to respond with something more helpful when a model isn't found ("No ModelRedirect matches the given query." is a red herring).

mattt commented 2 months ago

This is now fixed in v0.34.1.