Repository navigation
Migrate Providing_base_cases.ipynb to google-genai SDK (#446) - #1406
anushkamishra7 wants to merge 1 commit into
Conversation
|
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 migrates the Providing_base_cases.ipynb notebook to the modern google-genai SDK. The changes focus on updating the library imports, client initialization, and content generation patterns to align with current repository standards while ensuring stable execution. 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 Providing_base_cases.ipynb notebook to migrate from the deprecated google-generativeai library to the new google-genai SDK (version >=2.9.0). The changes include updating the installation command, adjusting imports, initializing the client using genai.Client(), introducing a MODEL_ID parameter selector, and updating the generation calls to use client.models.generate_content with types.GenerateContentConfig. The notebook outputs have also been updated to reflect the new model's responses. I have no feedback to provide as the changes align with the repository's style guide.
Giom-V
left a comment
There was a problem hiding this comment.
Hi @anushkamishra7, thanks a lot for tackling this migration!
However, this PR uses client.models.generate_content(), whereas we are now migrating our notebooks to the Interactions API (client.interactions.create() and interaction.output_text).
Could you please update the notebook to use client.interactions.create(model=MODEL_ID, input=..., system_instruction=instructions) and follow the setup structure shown in our Get Started guide?
Here are a couple of links to help you update it:
- Get_started.ipynb (see the System instructions section and how
client.interactions.createis used) - Template.ipynb (for the standard API key and SDK setup cell order)
Thanks again!
|
Thanks for the guidance! Happy to switch to the Interactions API. One thing worth flagging first: during testing, I'll go ahead and migrate to |
|
Marking this pull request as stale since it has been open for 14 days with no activity. This PR will be closed if no further activity occurs. |
What
Migrates
examples/prompting/Providing_base_cases.ipynbfrom the legacygoogle-generativeaiSDK togoogle-genai, per #446. Scope is this one notebook only — both call sites (genai.configure,genai.GenerativeModel) and nothing else.Why this notebook, and why now
#446 is closed, but the notebook was never migrated. Two earlier attempts exist and were both closed without merging:
Providing_base_cases.ipynbgoogle-generativeai SDK to google-genai SDK v1.0 with google colab #671 was closed in favor of Updated Providing_base_cases.ipynb to use google-genai #643.No open PR or issue currently claims this notebook. Per
CONTRIBUTING.md's guidance that small, well-scoped fixes can go straight to a PR, this skips re-opening #446 and goes directly to review.Changes
%pip install google-generativeai→%pip install "google-genai>=2.9.0"import google.generativeai as genai→from google import genai/from google.genai import typesgenai.configure(api_key=...)→client = genai.Client(api_key=...)genai.GenerativeModel(model_name=..., system_instruction=...)→ aMODEL_IDColab selector (the standard form used elsewhere in the repo) +types.GenerateContentConfig(system_instruction=...)passed per callmodel.generate_content(prompt)→client.models.generate_content(model=MODEL_ID, contents=prompt, config=...)Content and structure are otherwise unchanged: same two system-instruction examples (tourist assistant, library assistant), same four prompts, same on-topic/off-topic and specified/unspecified-genre comparisons. One markdown sentence was lightly reworded ("define the model" → "define a system instruction") since the new API has no persistent
modelobject, and the second example's redundant model-construction cell was removed sinceMODEL_IDis already defined and reused — the Interactions-API-style notebooks already migrated in this folder (e.g.Role_prompting.ipynb) follow the same one-selector-reused-across-examples shape.Why
client.models.generate_content()instead ofclient.interactions.create()The styleguide's default for new text-generation code is the Interactions API, but I hit a reproducible, serious reliability problem with it during testing and backed off to
client.models.generate_content()instead:client.interactions.create()call took ~70s for a one-line prompt.CLOSE_WAITwith zero CPU activity — the server had closed its end, but the client was blocked on a read that never returned.HttpOptions(timeout=...)) and upgraded to the latest SDK (2.27.0) to rule out a stale-version bug. A bounded retry with a 70-second watchdog still hung past the configured 45-second timeout, confirming the hang isn't something a caller can route around.client.models.generate_content()is the pattern already used by every other already-migrated notebook inexamples/prompting/(e.g.Basic_Classification.ipynb,Basic_Evaluation.ipynb), and it responded reliably in seconds throughout testing. Given the choice between matching the newer-but-currently-broken default and the older-but-stable, already-established pattern in this exact folder, I went with the latter and am flagging the Interactions API issue here rather than silently working around it.Verification
python tools/nbfmt_cli.py examples/prompting/Providing_base_cases.ipynb— passpython tools/nblint_cli.py examples/prompting/Providing_base_cases.ipynb— 0 errors, 2 pre-existing line-length warnings in the unmodifiedinstructionsprompt strings (present onmainbefore this change too)python tools/check_readme_links.py examples/prompting/Providing_base_cases.ipynb— linkedgemini-3.8-flash, and saved the real output.