Skip to content
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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

afiaka87
Copy link

@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?

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.")
Copy link
Member

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.

Copy link
Member

@zeke zeke left a 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.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await msg.edit(content="> Error. Please try again.")
await msg.edit(content="“{prompt}”\n> Error. Please try again.")

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