Skip to content

Migrate Search_Wikipedia_using_ReAct notebook to google-genai SDK#1100

Open
lahineers wants to merge 1 commit intogoogle-gemini:mainfrom
lahineers:migrate-react-genai
Open

Migrate Search_Wikipedia_using_ReAct notebook to google-genai SDK#1100
lahineers wants to merge 1 commit intogoogle-gemini:mainfrom
lahineers:migrate-react-genai

Conversation

@lahineers
Copy link

This PR migrates the Search_Wikipedia_using_ReAct notebook from the deprecated
google-generativeai SDK to the new google-genai SDK.

Changes:

  • Updated SDK imports and client usage
  • Removed deprecated APIs
  • Updated authentication to support Colab and local environments
  • Verified notebook logic remains unchanged

Fixes #446

@google-cla
Copy link

google-cla bot commented Jan 8, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@review-notebook-app
Copy link

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:examples Issues/PR referencing examples folder labels Jan 8, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @lahineers, 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 Search_Wikipedia_using_ReAct Jupyter notebook to utilize the latest google-genai SDK. This ensures the notebook remains compatible with current Google AI services, leverages the most up-to-date client libraries, and provides a more flexible authentication setup for various development environments. The underlying ReAct agent's functionality is preserved, focusing solely on the SDK transition.

Highlights

  • SDK Migration: The Search_Wikipedia_using_ReAct notebook has been migrated from the deprecated google-generativeai SDK to the new google-genai SDK.
  • API Updates: Key API calls and client initialization have been updated to align with the google-genai SDK's interface, including changes to generate_content and client instantiation.
  • Authentication Enhancement: The API key authentication mechanism has been improved to support both Google Colab environments (using userdata) and local/VS Code/Jupyter environments (using environment variables).
  • Notebook Logic Verification: The core logic of the ReAct agent within the notebook has been verified to remain unchanged, ensuring functionality after the SDK update.
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 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 counter productive. 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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

Copy link
Contributor

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

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 successfully migrates the Search_Wikipedia_using_ReAct notebook to the new google-genai SDK, updating the API client, authentication, and model-calling logic. The changes are mostly correct and improve the notebook's robustness by supporting both Colab and local environments.

I've identified a few areas for improvement:

  • The notebook's execution_count fields have been modified, which suggests the formatting script needs to be run as per the repository's style guide.
  • There are some minor style violations regarding code indentation and spacing.
  • A logic error was introduced in one of the final cells, which now contradicts its explanatory text by using the ReAct pipeline instead of making a direct model call.

My detailed comments provide specific suggestions to address these points.

Comment on lines +942 to +944
"gemini_ReAct_chat(\n",
" \"What is the total of ages of the main trio from the new Percy Jackson and the Olympians TV series in real life?\"\n",
")\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This change introduces a logical error. The markdown cell just before this one states: "Now, try asking the same question to gemini-2.0-flash model without the ReAct prompt." The original code correctly called the model directly, but the new code gemini_ReAct_chat(...) incorrectly uses the ReAct pipeline.

To fix this and align with the cell's purpose, you should make a direct call to the model using the client object.

client.models.generate_content(
    model="gemini-2.0-flash",
    contents="What is the total of ages of the main trio from the new Percy Jackson and the Olympians TV series in real life?"
).text

{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The execution_count for this and other cells has been changed from null. According to the repository style guide, this indicates that the notebook formatting script has not been run. Please run the formatting script before merging to ensure consistency.

References
  1. The style guide states that if execution_count is not null, it usually means the formatting script has not been run, and a warning should be raised to have the author run it. (link)

],
"source": [
"%pip install -q \"google-generativeai>=0.7.2\""
"%pip install -U -q \"google-genai\""
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The repository style guide recommends specifying a minimum version for the SDK installation to ensure notebook compatibility and prevent issues with future updates. Please add the version specifier to the pip install command.

%pip install -U -q "google-genai>=1.0.0"
References
  1. The style guide specifies that the SDK should be installed with a minimum version, for example: %pip install -U -q 'google-genai>=1.0.0'. (link)

Comment on lines +553 to +554
" self.client=genai.Client()\n",
" self.model=model\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To adhere to the Google Python Style Guide (and PEP 8), please add spaces around the assignment operators (=).

    self.client = genai.Client()
    self.model = model
References
  1. The style guide requires using the Google Python Style Guide, which follows PEP 8 for spacing around operators. (link)

Comment on lines +650 to +653
" response = self.client.models.generate_content(\n",
" model=self.model,\n",
" contents=f\"Return the first 2 or 3 sentences from the following text: {observation}\"\n",
" )\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The indentation for this multi-line function call does not follow the repository style guide. The arguments should be indented by one level (4 spaces) for better readability.

      response = self.client.models.generate_content(
          model=self.model,
          contents=f"Return the first 2 or 3 sentences from the following text: {observation}"
      )
References
  1. The style guide provides an example for formatting multi-line function calls, with indented parameters for readability. (link)

Comment on lines +805 to +809
" response = self.client.models.generate_content(\n",
" model=self.model,\n",
" contents=model_prompt,\n",
" **generation_kwargs\n",
")\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The indentation for this multi-line function call does not follow the repository style guide. The arguments should be indented by one level (4 spaces) for better readability.

    response = self.client.models.generate_content(
        model=self.model,
        contents=model_prompt,
        **generation_kwargs
    )
References
  1. The style guide provides an example for formatting multi-line function calls, with indented parameters for readability. (link)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update everything to use google-genai SDK

1 participant