Skip to content

fix(quickstarts): fix Nano Banana and Thinking quickstarts and migrate to Interactions API - #1331

Open
Giom-V wants to merge 4 commits into
google-gemini:mainfrom
Giom-V:fix/nano-banana-and-thinking-quickstarts
Open

fix(quickstarts): fix Nano Banana and Thinking quickstarts and migrate to Interactions API#1331
Giom-V wants to merge 4 commits into
google-gemini:mainfrom
Giom-V:fix/nano-banana-and-thinking-quickstarts

Conversation

@Giom-V

@Giom-V Giom-V commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR fixes the two remaining broken quickstart notebooks (Nano Banana and Thinking) by updating them to the current Google GenAI SDK Interactions API, fixing metadata parsing bugs, standardizing model selectors and parameters, formatting with nbfmt, and validating with nblint (0 errors, 0 warnings).

Changes

  1. Nano Banana Quickstart (quickstarts/Get_Started_Nano_Banana.ipynb):

    • Migrated all image generation, multi-turn editing, chaining (previous_interaction_id), and 4K upscaling to client.interactions.create.
    • Converted image inputs to standard base64 inline structures.
    • Fixed cell 50 NameError: name 'response' is not defined by inspecting interaction.steps for thought signatures.
    • Updated Wikipedia skyscraper test image thumbnail URL to standard 1280px and added Mozilla User-Agent to avoid Wikimedia download blocks.
    • Updated prose to second person ("you").
  2. Thinking Quickstarts (quickstarts/Get_started_thinking.ipynb and quickstarts/Get_started_thinking_REST.ipynb):

    • Fixed token usage metadata references to interaction.usage (resolving NameError on response).
    • Standardized thinking_level to allowed enum values ("low", "medium", "high").
    • Updated tool parameters to tools=[{"type": "code_execution"}] / [{"type": "google_search"}].
    • Fixed cell 9 URL split in the REST quickstart.
  3. QA & Testing Tools (tools/nb_tester)`:

    • Added default_rules.yaml timeout rule for Get_Started_Nano_Banana.ipynb (cell_timeout_sec: 180, notebook_timeout_sec: 1800).
    • Enhanced comparator.py to handle rich media representations (<Image: N>) when display data lacks plain text wrapper.

Verification

  • tools/nbfmt_cli.py applied to all modified notebooks.
  • tools/nblint_cli.py PASS (0 errors, 0 warnings).
  • tools.nb_tester executed with Gemini AI Security Audit verdict: SAFE (RiskScore=0/10) and live cell execution passing.

…e to Interactions API

- Update quickstarts/Get_Started_Nano_Banana.ipynb to Google GenAI SDK Interactions API:
  - Migrate image generation, editing, multi-turn chaining, and fusion to client.interactions.create
  - Fix cell 50 NameError on thought signatures by inspecting interaction.steps
  - Update Wikipedia skyscraper test image thumbnail URL and add Mozilla User-Agent to avoid 400/403 download blocks
  - Convert prose to second person ("you")
- Update quickstarts/Get_started_thinking.ipynb and Get_started_thinking_REST.ipynb:
  - Fix token usage metadata references on interaction.usage (resolve NameError on response)
  - Use valid thinking_level enum values ("low", "medium", "high")
  - Update tool parameters to [{"type": "code_execution"}] / [{"type": "google_search"}]
  - Fix cell 9 param line split in REST notebook
- Update tools/nb_tester:
  - comparator.py: Populate rich media indicators (<Image: N>) when display_data lacks plain text wrapper
  - rules/default_rules.yaml: Add execution timeout configuration for Nano Banana notebook
- Format all modified notebooks with tools/nbfmt_cli.py
@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@github-actions github-actions Bot added status:awaiting review PR awaiting review from a maintainer component:quickstarts Issues/PR referencing quickstarts folder labels Aug 19, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request updates the 'Nano Banana' and 'Thinking' quickstart notebooks to align with the latest Google GenAI SDK Interactions API. The changes ensure that model interactions, tool usage, and metadata handling are consistent and robust. Additionally, the QA testing infrastructure has been improved to better support rich media outputs and execution time management.

Highlights

  • API Migration: Migrated the 'Nano Banana' and 'Thinking' quickstart notebooks to the current Google GenAI SDK Interactions API.
  • Configuration Standardization: Standardized 'thinking_level' enum values and tool parameters across all updated notebooks for consistency.
  • Bug Fixes: Resolved metadata parsing issues, fixed token usage reference errors, and corrected NameErrors related to response handling.
  • QA Tooling Improvements: Enhanced the 'nb_tester' comparator to support rich media representations and added specific timeout rules for the Nano Banana notebook.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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

Copy link
Copy Markdown
Contributor

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 updates the thinking-related quickstart notebooks to align with the latest google-genai SDK standards, including transitioning to the interactions API, updating token usage properties, and adjusting how images are passed. It also improves the notebook tester's output comparator to handle non-textual cell outputs. Feedback on these changes highlights several critical issues: the REST notebook incorrectly uses "minimal" and "Minimal" for thinkingLevel (which only accepts lowercase "low", "medium", or "high"), the Python notebook uses generation_config instead of config in violation of the repository style guide, and a potential TypeError exists when converting step.arguments to a dictionary without checking if it is None.

" \"thinkingBudget\": 0\n",
" }\n",
" \"thinkingConfig\": {\n",
" \"thinkingLevel\": \"minimal\"\n",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The value "minimal" is not a valid value for thinkingLevel in the Gemini API. The allowed values are "low", "medium", and "high". Please change this to "low" to avoid API errors.

              "thinkingLevel": "low"

"\"\"\"\n",
"\n",
"thinkingBudget = 4096 # @param {type:\"slider\", min:0, max:24576, step:1}\n",
"thinkingLevel = \"High\" # @param [\"Minimal\", \"Low\", \"Medium\", \"High\"]\n",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The thinkingLevel parameter values should be lowercase ("low", "medium", "high") to match the allowed API values, and "Minimal" should be removed as it is not a valid level.

        thinkingLevel = "high"  # @param ["low", "medium", "high"]

Comment on lines +302 to +304
" generation_config={\n",
" \"thinking_level\": \"low\",\n",
" },\n",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

According to the repository style guide and the google-genai SDK standards, the configuration parameter for client.interactions.create should be named config, not generation_config.

      config={
          "thinking_level": "low",
      },
References
  1. The configuration parameter for client.interactions.create should be named config, not generation_config. (link)

Comment on lines +453 to +455
" generation_config={\n",
" \"thinking_level\": \"high\",\n",
" },\n",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

According to the repository style guide and the google-genai SDK standards, the configuration parameter for client.interactions.create should be named config, not generation_config.

    config={
        "thinking_level": "high",
    },
References
  1. The configuration parameter for client.interactions.create should be named config, not generation_config. (link)

Comment thread quickstarts/Get_started_thinking.ipynb Outdated
" if getattr(content, \"text\", None) is not None:\n",
" display(Markdown(content.text))\n",
" elif step.type == \"code_execution_call\":\n",
" code = dict(step.arguments).get(\"code\", \"\")\n",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

To prevent potential TypeError exceptions if step.arguments is None or missing, it is safer to use getattr and check if the arguments exist before converting them to a dictionary.

            arguments = getattr(step, "arguments", None)
            code = dict(arguments).get("code", "") if arguments else ""

@@ -212,7 +212,7 @@
},

@Giom-V Giom-V Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

gemini-3.1-flash-lite-image is missing, it should be replacing 2.5 as the cheapest and fastest model. 3.1 flash should be the default choice though but lite has a free tier which is why we're using it here.


Reply via ReviewNB

@@ -212,7 +212,7 @@
},

@Giom-V Giom-V Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Why did you change the model name? The default model shoud be gemini-3.1-flash-lite-image


Reply via ReviewNB

@@ -212,7 +212,7 @@
},

@Giom-V Giom-V Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Line #8.    def _extract_images_and_text(obj):

That seems overkill, have you tried using interaction.output_image?


Reply via ReviewNB

@@ -212,7 +212,7 @@
},

@Giom-V Giom-V Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

you simply call what? Also why did you remove the explanations about response_modalities?


Reply via ReviewNB

@@ -212,7 +212,7 @@
},

@Giom-V Giom-V Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Line #6.    

multiline prompts won't work with # @PARAM (same everywhere else)


Reply via ReviewNB

@@ -212,7 +212,7 @@
},

@Giom-V Giom-V Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Now we only have Gemini 3 models (2.5 has been replaced by lite), so we don't need a dedicated section anymore. Move the explanation at the begining (or remove it), remove the next cell


Reply via ReviewNB

@@ -212,7 +212,7 @@
},

@Giom-V Giom-V Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

remove this too and use the same model everywhere


Reply via ReviewNB

@@ -212,7 +212,7 @@
},

@Giom-V Giom-V Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

In each section, double check what NBP, NB2 and NB2Lite can do and document it (cf. https://ai.google.dev/gemini-api/docs/image-generation)


Reply via ReviewNB

@@ -212,7 +212,7 @@
},

@Giom-V Giom-V Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Line #6.        print(step.thought_signature)

Trim the output, it's way too big


Reply via ReviewNB

@@ -212,7 +212,7 @@
},

@Giom-V Giom-V Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Line #1.    text_prompt = "create a 1/7 scale commercialized figurine of the characters in the picture, in a realistic style, in a real environment. The figurine is placed on a computer desk. The figurine has a round transparent acrylic base, with no text on the base. The content on the computer screen is a 3D modeling process of this figurine. Next to the computer screen is a toy packaging box, designed in a style reminiscent of high-quality collectible figures, printed with original artwork. The packaging features two-dimensional flat illustrations."  # @param {type:"string"}

for all of that "Other cool prompts to test" section, we don't need @PARAM so use multiline strings for the prompts


Reply via ReviewNB

…output_image, previous_interaction_id, and multiline prompts
@kkorpal kkorpal self-assigned this Aug 21, 2026

@kkorpal kkorpal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I found a small syntax error in the Get_started_thinking_REST notebook I have resolved it and committed the changes to the same branch. Everything else looks good and there are no further errors, so we can proceed with merging this PR.

resolved: SyntaxError: expected ':'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component:quickstarts Issues/PR referencing quickstarts folder status:awaiting review PR awaiting review from a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants