-
Notifications
You must be signed in to change notification settings - Fork 115
Modifying the call_gemini_with_retries to remove retries to remove backoff. #5898
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
base: master
Are you sure you want to change the base?
Modifying the call_gemini_with_retries to remove retries to remove backoff. #5898
Conversation
… backoff. Modified related overview and follow up question calls accordingly.
Summary of ChangesHello @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 Highlights
🧠 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 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.
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".
| gemini_response = gemini.models.generate_content( | ||
| model=gemini_model, | ||
| contents=formatted_prompt, | ||
| config=generate_content_config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
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?
| page_overview = call_gemini(api_key=gemini_api_key, | ||
| formatted_prompt=formatted_page_overview_prompt, | ||
| schema=PageOverview, | ||
| gemini_model=_OVERVIEW_GEMINI_MODEL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
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?
beets
left a comment
There was a problem hiding this 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!
| gemini_response = gemini.models.generate_content( | ||
| model=gemini_model, | ||
| contents=formatted_prompt, | ||
| config=generate_content_config) |
There was a problem hiding this comment.
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?
| 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) |
There was a problem hiding this comment.
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?
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