chore(py): refactor folder organization for core plugins#5341
Open
huangjeff5 wants to merge 3 commits into
Open
chore(py): refactor folder organization for core plugins#5341huangjeff5 wants to merge 3 commits into
huangjeff5 wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request restructures the Python SDK by moving the core framework to the workspace root and consolidating plugins under src/genkit/plugins. Build targets, linting paths, and utility scripts were updated to accommodate this new layout. Key code changes include refactoring the Anthropic plugin's streaming logic and adding type narrowing in the OpenAI compatibility layer. Feedback suggests replacing type-narrowing assertions with more robust error handling for production stability and warns of potential runtime validation failures when passing internal Pydantic fields as keyword arguments.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Fixes two issues in the python repo:
1. Plugin imports never resolved in the IDE.
You get red squiggly lines in the IDE when you do
from genkit.plugins.google_genai import GoogleAIin across samples and tests. Runtime worked fine, but no static analyzer could resolve the import if you cloned the repo and tried to run a sample locally.The reason: each plugin lived in its own top-level directory (
py/plugins/<dash-name>/src/genkit/plugins/<underscore_name>/) while the rest of thegenkitpackage lived inpy/packages/genkit/src/genkit/. So from Python's perspective there were 10 different physical directories that all claimed to contribute modules to a single logical package,genkit.plugins.*. Static analyzers (pyright, pyrefly, ty) walk one source root at a time and don't merge them so even though runtime worked, IDEs with these type checkers would complain.2. The python repo had additional layers of nesting that don't need to exist, adding complexity.
py/packages/genkit/was a one-package directory that wrapped a single wheel. Once we'd already decided to pull plugin source into the core tree, there wasn't a good reason left for thepackages/wrapper to exist, and it added two extra path segments between the repo root andsrc/genkit/.This should be a refactor to simplify Genkit maintenance. There should be no visible impact to app developers.
Changes
Move plugin sources into the core genkit tree, and drop the
packages/genkit/wrapper at the same time.Plugins still ship as separate wheels on PyPI (
pip install genkit-plugin-google-genaistill installs only that plugin) — they just live in one tree on disk for the purposes of static analysis and contributor sanity. Each plugin keeps its ownpyproject.tomlnext to its source, which is what builds its wheel. The workspace, pyright, pyrefly, and ty configs all collapse from a list of nine source roots to one. The rootpy/pyproject.tomlnow serves both as the workspace config and as the wheel manifest for the coregenkitpackage (absorbing the oldpy/packages/genkit/pyproject.toml).Fix the type errors that this exposes.
A side effect of getting plugin imports to resolve is that, for the first time, pyright actually walks the plugin tree as part of repo-wide type-checking. It found roughly twenty latent type errors that had been there for months — most of them small (Pydantic field-alias positional vs. keyword arg, SDK union types that needed narrowing, an invariant collection signature where a covariant one was wanted). Each one is a real static-correctness fix; none of them change runtime behavior. Going forward, anyone editing plugin code gets type feedback in the IDE from the first character they type.
A few smaller workspace cleanups that come along with the move:
pluginsdependency group plusdefault-groups = [..., "plugins"]makesuv syncinstall every workspace plugin so monorepo contributors don't have to remember to install them by hand.websockets>=15.0is pinned as a direct dependency ofgenkit— it was previously transitive viagenkit-plugin-google-genai, which would have broken anyone installinggenkitstandalone (a latent bug that the layout cleanup happened to surface).Expected Outcomes
uv sync).