Migrate Search_Wikipedia_using_ReAct notebook to google-genai SDK#1100
Migrate Search_Wikipedia_using_ReAct notebook to google-genai SDK#1100lahineers wants to merge 1 commit intogoogle-gemini:mainfrom
Conversation
|
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. |
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Summary of ChangesHello @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 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 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 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
|
There was a problem hiding this comment.
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_countfields 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.
| "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" |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
- The style guide states that if
execution_countis notnull, 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\"" |
There was a problem hiding this comment.
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
- 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)
| " self.client=genai.Client()\n", | ||
| " self.model=model\n", |
There was a problem hiding this comment.
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
- The style guide requires using the Google Python Style Guide, which follows PEP 8 for spacing around operators. (link)
| " 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", |
There was a problem hiding this comment.
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
- The style guide provides an example for formatting multi-line function calls, with indented parameters for readability. (link)
| " response = self.client.models.generate_content(\n", | ||
| " model=self.model,\n", | ||
| " contents=model_prompt,\n", | ||
| " **generation_kwargs\n", | ||
| ")\n", |
There was a problem hiding this comment.
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
- The style guide provides an example for formatting multi-line function calls, with indented parameters for readability. (link)
This PR migrates the Search_Wikipedia_using_ReAct notebook from the deprecated
google-generativeai SDK to the new google-genai SDK.
Changes:
Fixes #446