-
Notifications
You must be signed in to change notification settings - Fork 2.7k
fix: Fix type mismatch in ContextFilterPlugin.custom_filter signature #4053
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: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @justinli34, 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 addresses a critical type inconsistency within the 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 correctly fixes a type mismatch in the ContextFilterPlugin.custom_filter signature, changing it from Callable[[List[Event]], List[Event]] to Callable[[List[types.Content]], List[types.Content]]. This aligns the type hint with its actual usage in before_model_callback, improving type safety. The change is well-described and necessary. I have one minor suggestion for consistency.
| num_invocations_to_keep: Optional[int] = None, | ||
| custom_filter: Optional[Callable[[List[Event]], List[Event]]] = None, | ||
| custom_filter: Optional[ | ||
| Callable[[List[types.Content]], List[types.Content]] |
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.
For consistency with other parts of the codebase (e.g., llm_request.py which uses list[types.Content]) and to align with the PR description, it would be better to use the built-in list type hint instead of typing.List. This is the modern approach for Python 3.9+ and seems to be adopted in other files. Using list here would also allow for the removal of the from typing import List import, which would become unused.
| Callable[[List[types.Content]], List[types.Content]] | |
| Callable[[list[types.Content]], list[types.Content]] |
Link to Issue or Description of Change
Problem:
The
ContextFilterPlugin.custom_filterparameter has an incorrect type signature. It's declared asCallable[[List[Event]], List[Event]]but is actually called withlist[types.Content]fromllm_request.contentsin thebefore_model_callbackmethod. This type mismatch could lead to runtime errors and prevents proper type checking.Solution:
Changed the type signature of
custom_filtertoCallable[[list[types.Content]], list[types.Content]]to match its actual usage. This ensures type safety and allows static type checkers to properly validate code that uses this plugin.Testing Plan
Unit Tests:
Existing unit tests continue to pass. The change is a type annotation fix that doesn't alter runtime behavior, so existing test coverage validates the fix.
Pytest output:
Manual End-to-End (E2E) Tests:
Type checking validation:
mypyon the modified file to confirm no type errorsChecklist
Additional context
This is a type annotation fix that improves type safety without changing runtime behavior. Users who have implemented custom filters may need to update their type hints if they were following the incorrect signature, though the runtime behavior remains unchanged.