Skip to content

Add prediction ID to ModelError exception #325

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

Closed
wants to merge 1 commit into from

Conversation

rohan-mehta
Copy link
Contributor

This is useful for debugging. For issue #324.

Signed-off-by: Rohan Mehta <rohanmehta@fastmail.com>
mattt added a commit that referenced this pull request Jul 18, 2024
This PR extends #325 to add the prediction object itself to
`ModelError`, as opposed to just its ID. This makes it convenient to
introspect logs and other information to determine how to handle the
failure.

```python
import replicate
from replicate.exceptions import ModelError

try:
  output = replicate.run("stability-ai/stable-diffusion-3", { "prompt": "..." })
except ModelError as e
  if "(some known issue)" in e.logs:
    pass

  print("Failed prediction: " + e.prediction.id)
```

---------

Signed-off-by: Rohan Mehta <rohanmehta@fastmail.com>
Signed-off-by: Mattt Zmuda <mattt@replicate.com>
Co-authored-by: Rohan Mehta <rohanmehta@fastmail.com>
@mattt
Copy link
Contributor

mattt commented Jul 18, 2024

This is a great idea. Thanks so much for sharing, @rohan-mehta!

I took this PR and ran with it a bit in #326. That PR updates ModelError to include the full prediction object as a field, so you can pull the ID, logs, or any other information as needed.

This is now available in 0.29.0.

@mattt mattt closed this Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants