Skip to content

Conversation

@shixiao-coder
Copy link
Contributor

This CL modifies the call to Gemini function for follow up question and modifies related interface with follow up question and overview.

The integration test for retry is also removed by this change

… backoff.

Modified related overview and follow up question calls accordingly.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @shixiao-coder, 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 streamlines the interaction with the Gemini API by centralizing retry logic outside the core call_gemini utility. By removing the built-in retry mechanism from the call_gemini_with_retries function (now simply call_gemini), the change simplifies the function's responsibility and allows for more flexible retry strategies to be implemented at a higher level if needed. This also involves updating all client-side calls and removing obsolete retry-specific tests.

Highlights

  • Gemini API Call Simplification: The call_gemini_with_retries function has been refactored to call_gemini, removing its internal retry mechanism and associated backoff logic.
  • Integration Updates: All existing calls to the Gemini API for generating page overviews and follow-up questions have been updated to use the new call_gemini function.
  • Test Suite Refinement: Corresponding integration tests that specifically verified the retry functionality have been removed, aligning the test suite with the updated API call behavior.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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 refactors the Gemini API call utility by removing retry logic, renaming "call_gemini_with_retries" to "call_gemini", and updating its call sites. While refactoring, the exception handling around the API call was inadvertently removed, which is a critical regression leading to unhandled server errors and potential denial of service. Additionally, two prompt injection vulnerabilities were identified where user input is directly concatenated into LLM prompts without sanitization. It is crucial to reintroduce robust exception handling, implement input sanitization, and consider simplifying the response handling logic in "gemini_utils.py".

Comment on lines +46 to +49
gemini_response = gemini.models.generate_content(
model=gemini_model,
contents=formatted_prompt,
config=generate_content_config)
Copy link
Contributor

Choose a reason for hiding this comment

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

security-medium medium

The removal of the try...except block for the gemini.models.generate_content call is a critical regression. This change introduces a denial of service vulnerability, as any failure in the Gemini API call will result in an unhandled exception. It is essential to reintroduce robust exception handling to prevent application crashes. Additionally, the response handling logic could be simplified.

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1, can we keep the try/except?

Comment on lines +81 to +84
page_overview = call_gemini(api_key=gemini_api_key,
formatted_prompt=formatted_page_overview_prompt,
schema=PageOverview,
gemini_model=_OVERVIEW_GEMINI_MODEL)
Copy link
Contributor

Choose a reason for hiding this comment

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

security-medium medium

The user-provided query and stat_var_titles (used to construct formatted_page_overview_prompt) are passed to the Gemini LLM without proper sanitization. This allows for prompt injection, where a malicious user could manipulate the prompt sent to the LLM. An attacker could potentially cause the LLM to ignore its original instructions, generate unintended content, or reveal information about the underlying prompt structure. The vulnerability lies in the construction of formatted_page_overview_prompt on lines 78-79, which is then used in the call_gemini function.

Comment on lines +315 to +319
follow_up_questions = call_gemini(
api_key=gemini_api_key,
formatted_prompt=formatted_follow_up_questions_prompt,
schema=FollowUpQuestions,
gemini_model=_QUESTIONS_GEMINI_MODEL,
retries=_QUESTIONS_GEMINI_CALL_RETRIES,
)
gemini_model=_QUESTIONS_GEMINI_MODEL)
Copy link
Contributor

Choose a reason for hiding this comment

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

security-medium medium

The user-provided query and related_topics (used to construct formatted_follow_up_questions_prompt) are passed to the Gemini LLM without proper sanitization. This allows for prompt injection, where a malicious user could manipulate the prompt sent to the LLM. An attacker could potentially cause the LLM to ignore its original instructions, generate unintended content, or reveal information about the underlying prompt structure. The vulnerability lies in the construction of formatted_follow_up_questions_prompt on lines 312-313, which is then used in the call_gemini function.

Copy link
Collaborator

Choose a reason for hiding this comment

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

in a follow up, can we update the prompt to protect against this?

Copy link
Collaborator

@beets beets left a comment

Choose a reason for hiding this comment

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

thanks for the quick turnaround!

Comment on lines +46 to +49
gemini_response = gemini.models.generate_content(
model=gemini_model,
contents=formatted_prompt,
config=generate_content_config)
Copy link
Collaborator

Choose a reason for hiding this comment

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

+1, can we keep the try/except?

Comment on lines +315 to +319
follow_up_questions = call_gemini(
api_key=gemini_api_key,
formatted_prompt=formatted_follow_up_questions_prompt,
schema=FollowUpQuestions,
gemini_model=_QUESTIONS_GEMINI_MODEL,
retries=_QUESTIONS_GEMINI_CALL_RETRIES,
)
gemini_model=_QUESTIONS_GEMINI_MODEL)
Copy link
Collaborator

Choose a reason for hiding this comment

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

in a follow up, can we update the prompt to protect against this?

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.

2 participants