Repository navigation
Add Gemini native image generation - #147
Merged
Merged
Conversation
kafkasl
commented
Dec 1, 2026
| def payload_kwargs(msgs, model, stream=False, system=None, max_tokens=None, temperature=None, tools=None, tool_choice=None, | ||
| parallel_tool_calls=None, previous_response_id=None, prompt_cache_key=None, reasoning_effort=None, web_search_options=None, | ||
| cache_idxs=None, ttl=None, stop_callables=None): pass | ||
| cache_idxs=None, ttl=None, stop_callables=None, response_modalities=None, image_config=None): pass |
Contributor
Author
There was a problem hiding this comment.
response_modalities and image_config (Gemini's options for requesting image output and aspect ratio/size) sit directly on payload_kwargs rather than inside a Gemini-only wrapper, matching Anthropic-only cache_idxs and ttl, which other providers ignore.
kafkasl
commented
Dec 1, 2026
| return FinishReason.tool_calls if r==FinishReason.stop and any(~L(tcs).attrgot('server')) else r | ||
|
|
||
| # %% ../nbs/07_gemini.ipynb #11b4fd46 | ||
| def _is_inline_img(p): return 'inlineData' in p and p['inlineData'].get('mimeType', 'image/png').startswith('image/') |
Contributor
Author
There was a problem hiding this comment.
Checks mimeType.startswith('image/') so non-image inlineData stays out of OutputImage. Below in norm_parts, thought: True parts without 'text' (thought images) are skipped so non-streaming matches norm_sse_event.
kafkasl
commented
Dec 1, 2026
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "png_b64 = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGP4z8DwHwAFAAH/iZk9HQAAAABJRU5ErkJggg=='\n", |
Contributor
Author
There was a problem hiding this comment.
Uses a tiny synthetic PNG for the offline lessons instead of adding a ~1 MB generated image to cachy.jsonl.
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.
Added native Gemini image generation (using
models/gemini-nano-banana-2.1) by returning generated images asOutputImageparts and pricing image output tokens at the model's image token rate.The
OutputImageis a new part added in this small aidialog PR AnswerDotAI/aidialog#76.Generated images come back as
OutputImageparts containing a base64 data URL. Callers can display them in notebooks or save them to disk. To edit an image, send the saved file back as a userInputImagein a new turn, or continue the sameAsyncChat.AsyncChatresends Gemini's savedMsg.rawverbatim, keeping itsthoughtSignatureintact.Depends on AnswerDotAI/aidialog#76. Stacked on #146.