fix: add function_response check to _part_has_payload#4356
fix: add function_response check to _part_has_payload#4356filipecaixeta wants to merge 1 commit intogoogle:mainfrom
Conversation
The _part_has_payload function was not checking for function_response content, causing _append_fallback_user_content_if_missing to add the fallback message "Handle the requests as specified in the System Instruction." even when a valid function response was present. This fix adds a check for part.function_response.response to properly detect when a Part contains function response payload. Added unit tests for: - _part_has_payload function with various payload types - _append_fallback_user_content_if_missing with function_response
Summary of ChangesHello @filipecaixeta, 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 refines the logic for handling 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.
Code Review
This pull request correctly addresses an issue where a fallback user message was being added unnecessarily for messages containing a function_response. The fix in _part_has_payload is simple and effective. The newly added unit tests are comprehensive, covering both the changed function and the dependent logic in _append_fallback_user_content_if_missing, which ensures the fix is robust and prevents regressions. The code quality is excellent. Great work!
|
I'm closing this PR since someone was faster and solved it already |
Summary
function_responsecheck to_part_has_payloadfunction inlite_llm.py_append_fallback_user_content_if_missingwas adding the fallback message "Handle the requests as specified in the System Instruction." even when a valid function response was present in user content_part_has_payloadand_append_fallback_user_content_if_missingwith function_response scenariosProblem
The
_part_has_payloadfunction checks whether aPartcontains usable payload for the model, but it was missing a check forfunction_response. This caused the fallback user content to be injected unnecessarily when a user message contained only a function response, leading to:Changes
src/google/adk/models/lite_llm.py:tests/unittests/models/test_litellm.py:TestPartHasPayloadclass with 6 unit testsTestAppendFallbackUserContentIfMissingclass with 5 unit testsTest plan
test_generate_content_async_adds_fallback_user_message,test_maybe_append_user_content)