Skip to content

Add prediction ID to ModelError exception#325

Closed
rohan-mehta wants to merge 1 commit intoreplicate:mainfrom
rohan-mehta:main
Closed

Add prediction ID to ModelError exception#325
rohan-mehta wants to merge 1 commit intoreplicate:mainfrom
rohan-mehta:main

Conversation

@rohan-mehta
Copy link
Copy Markdown
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
Copy Markdown
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