Skip to content

feat: add Google AI Studio Gemini image generation plugin - #1

Merged
gabbyong merged 5 commits into
mainfrom
feat/nano-banana-plugin
Oct 8, 2026
Merged

gabbyong merged 5 commits into
mainfrom
feat/nano-banana-plugin

Conversation

@gabbyong

@gabbyong gabbyong commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds the native Google AI Studio Gemini (Nano Banana) image generation and editing backend plugin (gemini-image) for Hermes Agent, using GEMINI_API_KEY against POST /v1beta/models/{model}:generateContent.

Key Features

  • Supported models: gemini-3.1-flash-image (Nano Banana 2, default), gemini-3.1-flash-lite-image (Nano Banana 2 Lite), and gemini-3-pro-image (Nano Banana Pro).
  • Generation & editing controls: Supports up to 14 reference images (remote URLs, data: URIs, or local paths), model-gated aspect ratios (up to 14 ratios on 3.1 Flash), output resolutions (512, 1K, 2K, 4K), and optional Google Search grounding via config.yaml (image_gen.gemini.*).
  • Safety & accounting: Enforces Hermes SSRF and local file-safety guards, magic-byte MIME sniffing, a 25 MB per-image / 80 MB total inline payload cap, and session token usage reporting (including thinking tokens).
  • Tests: Includes 32 unit tests (tests/test_gemini_provider.py) covering setup schema readiness, model resolution, reference image validation, and wire payload formatting.
  • Apache 2.0 licensing.

Future Work

  • Refactor the repository structure to support multiple Gemini plugins (not just image-gen) under google-gemini/hermes-gemini-api-plugin (this initial PR focuses on shipping the gemini-image plugin first).

Previous Work:

Add the native Google AI Studio Gemini (Nano Banana 2, Nano Banana 2 Lite, and Nano Banana Pro) image generation and editing backend plugin for Hermes Agent, along with unit tests and Apache 2.0 licensing.
@gabbyong
gabbyong requested a review from osanseviero October 5, 2026 07:08

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new Google AI Studio Gemini image generation plugin, including its implementation, configuration, and a comprehensive test suite, while removing the legacy NOTICE file and updating the README. The review feedback highlights three important areas for improvement: addressing a potential Denial of Service (DoS) vulnerability when reading non-regular local files, relaxing base64 decoding validation to gracefully handle whitespaces or line wraps in data URIs, and correcting the upscaling logic to prioritize 4K resolution over 2K when both are supported.

Comment thread __init__.py Resolved
Comment thread __init__.py Resolved
Comment thread __init__.py Resolved
1. upscale request - prioritise 4K if available, then 2K resolution
2. raw = base64.b64decode(b64) remove Validate=True to gracefully ignore whitespace & newlines. `_sniff_mime` on line 295 still guarantees the decoded bytes start with valid PNG, JPEG, WebP, or GIF magic headers.
3. Add "path is a regular file" verification before reading image

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@gabbyong
gabbyong requested a review from philschmid October 5, 2026 14:16

@philschmid philschmid left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can you check against the internal docs we have it seems that we are missing some pieces as the Notice in the README that this is not an official google product etc.

Comment thread tests/test_gemini_provider.py Resolved
Replaces the short SPDX snippet headers with the full 13-line Apache 2.0 header, restores the unmodified Apache 2.0 LICENSE appendix, updates the repository name in CODEOWNERS, and adds the Gemini API Terms of Service link to the README disclaimer. Also strips ASCII whitespace from RFC 2397 data URI payloads before strict base64 validation and adds a corresponding unit test.
@gabbyong

gabbyong commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Updated:

  • 13-line Apache 2.0 headers — Replaced the short 2-line SPDX headers with the full 13-line Google Apache 2.0 header in init.py, plugin.yaml, and tests/test_gemini_provider.py.
  • Unmodified LICENSE appendix — Restored the standard Apache 2.0 APPENDIX: How to apply the Apache License to your work boilerplate at the end of LICENSE
  • Updated CODEOWNERS comment — Fixed the repository name comment on line 1 of .github/CODEOWNERS to google-gemini/hermes-gemini-api-plugin.
  • Gemini API Terms link — Added the Gemini API Additional Terms of Service link to the Disclaimer section of README.md.
  • [lint] Whitespace-tolerant data: URI check — Stripped ASCII whitespace via b64 = "".join(b64.split()) before the length bound and base64.b64decode(b64, validate=True) in _load_image_bytes, and added test_load_image_bytes_decodes_whitespace_wrapped_data_uri_and_rejects_corrupt_b64 (33/33 tests passing).

Adds Gemini Nano Banana 2.1 (gemini-nano-banana-2.1) as the default image generation model with 14 aspect ratios, 1K/2K/4K output resolutions, and Google Web and Image Search grounding, while keeping Nano Banana 2 (gemini-3.1-flash-image), Nano Banana 2 Lite (gemini-3.1-flash-lite-image), and Nano Banana Pro (gemini-3-pro-image) in the model catalog. Updates the README supported models table and unit tests to cover all four catalog entries and per-model resolution gating.
@gabbyong
gabbyong requested review from markmcd and philschmid October 7, 2026 03:25

@markmcd markmcd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just a couple of small nits - otherwise looks pretty comprehensive. LGTM!

Comment thread tests/test_gemini_provider.py Resolved
Comment thread tests/test_gemini_provider.py Resolved
Comment thread tests/test_gemini_provider.py Resolved
Asserts provider.default_model() against gemini_plugin.DEFAULT_MODEL, uses subset comparison (>=) for catalog model IDs so future model additions do not break the picker test, and switches fake test API keys from AIza- to AQ. prefixes to avoid secret-scanner false positives.
@gabbyong
gabbyong merged commit ceb9a1f into main Oct 8, 2026
6 checks passed
@gabbyong
gabbyong deleted the feat/nano-banana-plugin branch October 8, 2026 11:08
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.

3 participants