fix(quickstarts): fix Nano Banana and Thinking quickstarts and migrate to Interactions API - #1331
Conversation
…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
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Summary of ChangesHello, 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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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", |
| "\"\"\"\n", | ||
| "\n", | ||
| "thinkingBudget = 4096 # @param {type:\"slider\", min:0, max:24576, step:1}\n", | ||
| "thinkingLevel = \"High\" # @param [\"Minimal\", \"Low\", \"Medium\", \"High\"]\n", |
| " generation_config={\n", | ||
| " \"thinking_level\": \"low\",\n", | ||
| " },\n", |
There was a problem hiding this comment.
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
- The configuration parameter for client.interactions.create should be named config, not generation_config. (link)
| " generation_config={\n", | ||
| " \"thinking_level\": \"high\",\n", | ||
| " },\n", |
There was a problem hiding this comment.
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
- The configuration parameter for client.interactions.create should be named config, not generation_config. (link)
| " 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", |
There was a problem hiding this comment.
…d safe step arguments access
| @@ -212,7 +212,7 @@ | |||
| }, | |||
There was a problem hiding this comment.
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 @@ | |||
| }, | |||
There was a problem hiding this comment.
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 @@ | |||
| }, | |||
There was a problem hiding this comment.
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 @@ | |||
| }, | |||
There was a problem hiding this comment.
you simply call what? Also why did you remove the explanations about response_modalities?
Reply via ReviewNB
| @@ -212,7 +212,7 @@ | |||
| }, | |||
| @@ -212,7 +212,7 @@ | |||
| }, | |||
There was a problem hiding this comment.
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 @@ | |||
| }, | |||
There was a problem hiding this comment.
| @@ -212,7 +212,7 @@ | |||
| }, | |||
There was a problem hiding this comment.
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 @@ | |||
| }, | |||
There was a problem hiding this comment.
| @@ -212,7 +212,7 @@ | |||
| }, | |||
There was a problem hiding this comment.
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
resolved: SyntaxError: expected ':'
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 withnblint(0 errors, 0 warnings).Changes
Nano Banana Quickstart (
quickstarts/Get_Started_Nano_Banana.ipynb):previous_interaction_id), and 4K upscaling toclient.interactions.create.NameError: name 'response' is not definedby inspectinginteraction.stepsfor thought signatures.Thinking Quickstarts (
quickstarts/Get_started_thinking.ipynbandquickstarts/Get_started_thinking_REST.ipynb):interaction.usage(resolvingNameErroronresponse).thinking_levelto allowed enum values ("low","medium","high").tools=[{"type": "code_execution"}] / [{"type": "google_search"}].QA & Testing Tools (
tools/nb_tester)`:default_rules.yamltimeout rule forGet_Started_Nano_Banana.ipynb(cell_timeout_sec: 180,notebook_timeout_sec: 1800).comparator.pyto handle rich media representations (<Image: N>) when display data lacks plain text wrapper.Verification
tools/nbfmt_cli.pyapplied to all modified notebooks.tools/nblint_cli.pyPASS (0 errors, 0 warnings).tools.nb_testerexecuted with Gemini AI Security Audit verdict: SAFE (RiskScore=0/10) and live cell execution passing.