-
Notifications
You must be signed in to change notification settings - Fork 35
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
Handle any ModelError
raised by replicate
#6
base: main
Are you sure you want to change the base?
Conversation
image = model.predict(prompt=prompt)[0] | ||
except replicate.exceptions.ModelError as ex: | ||
if "NSFW" in str(ex): # model output was classified as NSFW | ||
await msg.edit(content="> NSFW detected. Please try again.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should also include the original prompt in this message, so people know which one(s) failed, in case multiple simultaneous predictions are in flight.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this. That change looks good. Just one suggestion.
image = model.predict(prompt=prompt)[0] | ||
except replicate.exceptions.ModelError as ex: | ||
if "NSFW" in str(ex): # model output was classified as NSFW | ||
await msg.edit(content="> NSFW detected. Please try again.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await msg.edit(content="> NSFW detected. Please try again.") | |
await msg.edit(content="“{prompt}”\n> NSFW detected. Please try again.") |
await msg.edit(content="> NSFW detected. Please try again.") | ||
else: # something else went wrong, log to console so developer can debug | ||
print(ex) | ||
await msg.edit(content="> Error. Please try again.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await msg.edit(content="> Error. Please try again.") | |
await msg.edit(content="“{prompt}”\n> Error. Please try again.") |
@zeke Have been using this code a for a custom bot actually. Super handy for testing models. I notice we don't handle any errors raised by the replicate package. This presently happens when we flag an NSFW output, but can happen for other reasons too.
It's unfortunately not nearly as clean - and tutorial code should probably be clean and simple. Any ideas?