Repository navigation
Add OutputImage message part for generated images - #76
Merged
Merged
Conversation
kafkasl
commented
Dec 1, 2026
|
|
||
| # %% ../nbs/00_msg_parts.ipynb #e75741cc | ||
| @patch(as_prop=True) | ||
| def formatted(self:OutputImage): return self.ctext |
Contributor
Author
There was a problem hiding this comment.
avoid returning the huge data:image/png;base64,... string and returns ctext, which in this case will be <media output_image image/png>
kafkasl
commented
Dec 1, 2026
| @patch(as_prop=True) | ||
| def formatted(self:OutputImage): return self.ctext | ||
| @patch | ||
| def doc(self:OutputImage, showthink=False, mx=2000): return f'' if self.text else '' |
Contributor
Author
There was a problem hiding this comment.
return the image as  so it renders properly in solveit after hist2fmt
kafkasl
commented
Dec 1, 2026
Comment on lines
+1998
to
+2007
| "source": [ | ||
| "out_img = OutputImage('data:image/png;base64,xxx', mime='image/png')\n", | ||
| "test_eq(out_img.formatted, '<media output_image image/png>')\n", | ||
| "test_eq(out_img.doc(), '')\n", | ||
| "test_eq(out_img._repr_markdown_(), '')\n", | ||
| "test_eq(OutputImage(mime='image/png').doc(), '')\n", | ||
| "test_eq(OutputImage(mime='image/png')._repr_markdown_(), '<media output_image image/png>')\n", | ||
| "test_eq(mk_part(**_part2dict(out_img)), out_img)" | ||
| ] | ||
| }, |
Contributor
Author
There was a problem hiding this comment.
This test checks plain-text formatting, Markdown rendering, empty-data fallbacks, and round-trip serialization.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is used by AnswerDotAI/fastllm#147 to add image generation capabilities to fastllm.
Message parts currently cover media sent into a model (images, audio, video, files), with no part type for images generated in an assistant reply.
I added an
OutputImagemedia part so providers such as Gemini can return generated images alongside text. Plain-text formatting emits the compact<media>tag instead of dumping base64 data. Markdown rendering embeds the image when image data is present and falls back when empty.