fix(py): handle nullable JSON Schema types in Gemini plugin and clean up samples#4629
fix(py): handle nullable JSON Schema types in Gemini plugin and clean up samples#4629
Conversation
Summary of ChangesHello @yesudeep, 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 focuses on improving the robustness and correctness of the Python Genkit framework. It addresses critical issues related to 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. Changelog
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
|
d893474 to
6e43f05
Compare
… up samples - Fix _convert_schema_property in the Gemini plugin to handle JSON Schema nullable types where `type` is a list (e.g. `['string', 'null']`) instead of a single string. Extracts the non-null type and sets `schema.nullable = True` on the Gemini Schema object.
6e43f05 to
9104f85
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces several important fixes and cleanups across various plugins and samples. The fix to preserve structlog configuration when adding new processors is crucial, though it introduces some code duplication that could be refactored. The changes to handle ReasoningPart for DeepSeek and nullable types in the Gemini plugin correctly address API compatibility and schema handling issues. Additionally, the cleanup in the samples, such as replacing Decimal with float and improving flow return types, enhances code quality and maintainability. The added tests for the ReasoningPart stripping logic are also a great addition, ensuring the fix is well-covered. Overall, these are solid improvements.
I am having trouble creating individual review comments. Click here to see my feedback.
py/plugins/amazon-bedrock/src/genkit/plugins/amazon_bedrock/telemetry/tracing.py (367-374)
This logic to re-configure structlog while preserving existing settings is a great fix to avoid wiping out other configurations. However, this exact block of code has been duplicated in several other plugin telemetry files:
py/plugins/cloudflare-workers-ai/src/genkit/plugins/cloudflare_workers_ai/telemetry/tracing.pypy/plugins/google-cloud/src/genkit/plugins/google_cloud/telemetry/tracing.pypy/plugins/microsoft-foundry/src/genkit/plugins/microsoft_foundry/telemetry/tracing.pypy/plugins/observability/src/genkit/plugins/observability/__init__.py
To improve maintainability and reduce code duplication (D.R.Y. principle), consider extracting this logic into a shared utility function within a core module (e.g., genkit.core.tracing or a new logging utility module).
For example, you could create a helper:
# In a shared utility file
import structlog
def reconfigure_structlog_processors(new_processors: list) -> None:
"""Safely adds new processors to structlog without overwriting other settings."""
cfg = structlog.get_config()
structlog.configure(
processors=new_processors,
wrapper_class=cfg.get('wrapper_class'),
context_class=cfg.get('context_class'),
logger_factory=cfg.get('logger_factory'),
cache_logger_on_first_use=cfg.get('cache_logger_on_first_use'),
)Then, each plugin could simply call reconfigure_structlog_processors(new_processors).
fix(py): handle nullable JSON Schema types in Gemini plugin and clean up samples
Schema nullable types where
typeis a list (e.g.['string', 'null'])instead of a single string. Extracts the non-null type and sets
schema.nullable = Trueon the Gemini Schema object.