-
Notifications
You must be signed in to change notification settings - Fork 16
added stability text-to-image job #59
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
Conversation
nicktrn
left a comment
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 @gjohnsx, thanks for your contribution!
Think you forgot to link the issue. If you edit your post to add closes #47 or fixes #47 the issue can be automatically closed on merge. Makes things easier on our end! 🙏
Left some comments.
src/stability.ts
Outdated
| const images = await io.runTask( | ||
| "Create image from text", | ||
| async () => { | ||
| const response = await fetch( |
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.
I think we should use io.backgroundFetch() for the reasons explained here. This can be used outside of io.runTask() so we don't create an unnecessary subtask.
src/stability.ts
Outdated
| images.artifacts.forEach((image, index) => { | ||
| const imageUrl = `data:image/png;base64,${image.base64}`; | ||
| // Log the URL to the console | ||
| io.logger.info(`Image ${index + 1}/${payload.samples ?? 1}:`, { |
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.
This is a great example of how to correctly use cacheKeys within loops! Will be useful for people to adapt to their needs.
The only issue here is the use of forEach(). This will not work as expected, especially with real subtasks. We should probably use async iteration with for (const artifact of images.artifacts) { await ... } or alternatively await Promise.all(images.artifacts.map(..)).
|
@nicktrn thank you very much for the tips and for the comments! I changed the first io.runTask to io.backgroundFetch. Take a look and let me know if that looks good. Test payload: |
Looks good! You can make things even simpler by removing the typecast and passing it like this: io.backgroundFetch<GenerationResponse>(...)
Sure, that's fine. My main concern was people adapting the previous example without realising they're creating (async) tasks within a |

I added a text-to-image job using the Stability AI REST API.
I wasn't sure what to do with the image in the example job so I'm just logging the huge base64 url
If you have any other ideas for what to do with the artifacts once returned I'm all ears!