-
Notifications
You must be signed in to change notification settings - Fork 616
fix(py): update define_embedder in google plugin_api and other test files #3964
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
fix(py): update define_embedder in google plugin_api and other test files #3964
Conversation
Summary of ChangesHello @MengqinShen, 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 introduces a more structured approach to defining embedder metadata within the Genkit framework. By modifying the Highlights
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 define_embedder function in genkit/ai/_registry.py to accept an explicit metadata parameter and streamlines its internal handling. The primary change involves transitioning how embedder configuration is passed from a raw metadata dictionary to a structured EmbedderOptions object across the Google GenAI and Ollama plugins. This required updating the initialize and _resolve_embedder methods in google.py and plugin_api.py to construct and pass EmbedderOptions containing details like label, dimensions, supports, and config_schema. Corresponding unit tests in test_google_plugin.py and test_plugin_api.py were updated to reflect this new EmbedderOptions usage. Review comments suggested a more concise dictionary initialization using metadata or {} in _registry.py and recommended unpacking the supports dictionary more robustly in the Google plugin tests to handle future EmbedderSupports field additions.
|
/gemini review |
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 updates the define_embedder function signature and its usage across various plugins, centralizing embedder configurations into an EmbedderOptions object. The changes are logical and consistently applied. My review focuses on improving the robustness of the associated tests to ensure they accurately reflect the implementation's behavior, especially in edge cases. I've provided specific suggestions to align the test logic with the production code.
| options = EmbedderOptions( | ||
| label=info.get('label'), | ||
| supports=EmbedderSupports(**info.get('supports', {})), | ||
| dimensions=info.get('dimensions'), | ||
| ) |
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 logic for constructing EmbedderOptions, specifically for the supports field, diverges from the implementation in google.py. The implementation results in supports=None if the supports dictionary is missing or empty, while this test would create an EmbedderSupports object with default values. This discrepancy could lead to the test failing incorrectly if default_embedder_info changes its return value in the future. To ensure consistency and robustness, the test should replicate the implementation's logic.
| options = EmbedderOptions( | |
| label=info.get('label'), | |
| supports=EmbedderSupports(**info.get('supports', {})), | |
| dimensions=info.get('dimensions'), | |
| ) | |
| options = EmbedderOptions( | |
| label=info.get('label'), | |
| supports=EmbedderSupports(**s) if (s := info.get('supports')) else None, | |
| dimensions=info.get('dimensions'), | |
| ) | |
| options = EmbedderOptions( | ||
| label=info.get('label'), | ||
| supports=EmbedderSupports(**info.get('supports', {})), | ||
| dimensions=info.get('dimensions'), | ||
| ) |
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.
Similar to a previous comment, the logic for constructing EmbedderOptions here is inconsistent with the implementation in google.py. The implementation sets supports to None if the supports data is missing or empty, but this test creates an EmbedderSupports object with default values. This should be aligned to ensure the test is accurate and robust against future changes.
| options = EmbedderOptions( | |
| label=info.get('label'), | |
| supports=EmbedderSupports(**info.get('supports', {})), | |
| dimensions=info.get('dimensions'), | |
| ) | |
| options = EmbedderOptions( | |
| label=info.get('label'), | |
| supports=EmbedderSupports(**s) if (s := info.get('supports')) else None, | |
| dimensions=info.get('dimensions'), | |
| ) | |
This is to solve the issue #3952.
CHANGELOG: