Skip to content

fix: correct NoneType object error #1979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Sanmilee
Copy link

@Sanmilee Sanmilee commented Apr 16, 2025

Description

Thank you for opening a Pull Request!
Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Follow the CONTRIBUTING Guide.
  • You are listed as the author in your notebook or README file.
    • Your account is listed in CODEOWNERS for the file(s).
  • Make your Pull Request title in the https://www.conventionalcommits.org/ specification.
  • Ensure the tests and linter pass (Run nox -s format from the repository root to format).
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

@Sanmilee Sanmilee requested a review from a team as a code owner April 16, 2025 22:38
Copy link

@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.

Hello @Sanmilee, 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!

Summary of Changes

This pull request addresses a NoneType object error in the use_case_company_news_and_insights.ipynb notebook. The primary change involves adding a try-except block to handle potential AttributeError exceptions that can occur when accessing the function_call.name attribute of a Gemini API response. Additionally, the PR includes updates to execution counts, adds the author to the notebook, and incorporates a helper function to extract function calls from the API response. The prompt given to the LLM is also updated to include a request for a concise, high-level summary.

Highlights

  • Error Handling: Implements a try-except block to gracefully handle AttributeError exceptions when processing Gemini API responses, preventing the notebook from crashing when a function call is not present.
  • Function Call Extraction: Adds a helper function extract_function_calls to parse and extract function calls from a Gemini GenerationResponse, facilitating easier access to function names and arguments.
  • Prompt Update: Modifies the prompt sent to the Gemini API to explicitly request a concise, high-level summary, improving the quality of the generated responses.
  • Author Addition: Adds the author, Ariyo Oluwasanmi, to the notebook's author list.

Changelog

  • gemini/function-calling/use_case_company_news_and_insights.ipynb
    • Added Ariyo Oluwasanmi to the author list.
    • Set initial execution count to null.
    • Updated execution counts for various code cells.
    • Imported GenerationResponse from vertexai.generative_models.
    • Added a helper function extract_function_calls to extract function calls from the API response.
    • Added a try-except block to handle AttributeError when extracting function call names.
    • Updated the prompt to request a concise, high-level summary.
    • Modified the API key to be commented out by default.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 is currently in preview and 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 to provide feedback.

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.


A null's cold embrace,
Breaks code, halts its steady pace.
Try/Except's warm guard.

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

@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

The pull request aims to fix a NoneType object error in the use_case_company_news_and_insights.ipynb notebook. The changes include adding a new author, updating execution counts, importing GenerationResponse, commenting out the API key, modifying the send_chat_message function to handle multiple function calls, and updating the outputs of several code cells. Overall, the changes seem to address the error and improve the functionality of the notebook.

Summary of Findings

  • Error Handling in send_chat_message: The send_chat_message function now uses a broad AttributeError exception to handle cases where a natural language response is received instead of a function call. While this addresses the immediate error, it might mask other potential AttributeError exceptions that could occur within the try block. A more specific exception handling approach would be beneficial.
  • Inconsistent Output Formatting: The output formatting in the notebook is inconsistent. Some cells display '#### Predicted function name' while others display '#### Function Extraction' for the same purpose. Standardizing the output format would improve readability.
  • API Key Security: The API key is commented out in the notebook. While this prevents accidental exposure, it also means the notebook won't function correctly without the user providing their own key. Consider providing instructions on how to obtain and set the API key.

Merge Readiness

The pull request addresses the reported error and introduces some improvements to the notebook. However, the broad exception handling in send_chat_message and the inconsistent output formatting should be addressed before merging. Additionally, clear instructions on setting up the API key are necessary for the notebook to be functional. I am unable to approve this pull request, and recommend that others review and approve this code before merging.

@holtskinner holtskinner requested a review from koverholt April 17, 2025 15:30
@holtskinner holtskinner changed the title fix: correct NoneType object error fix: correct NoneType object error Apr 17, 2025
@Sanmilee
Copy link
Author

@holtskinner, thanks for your prompt review. The PR has been revised!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants