Repository navigation
feat(py): share GoogleCloud backend config and ADC helpers in genkit.plugin_api - #195
Closed
huangjeff5 wants to merge 2 commits into
Closed
huangjeff5 wants to merge 2 commits into
huangjeff5 wants to merge 2 commits into
Conversation
Collaborator
Author
|
Closing: keeping |
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.
Adds a shared
GoogleCloud(project=None, location=None)backend config and shared Google Cloud ADC/resolution helpers togenkit.plugin_api, so plugins that support Google Cloud backends (Anthropic(backend=GoogleCloud())in #151,OpenAICompatible(backend=GoogleCloud())in #188) share one class and one credential-loading path while keeping top-levelgenkitfocused on core primitives.Changes
GoogleClouddataclass ingenkit.plugin_api(packages/genkit/src/genkit/_core/_google_cloud.py, exported fromgenkit.plugin_api):GoogleCloud(project: str | None = None, location: str | None = None).genkitcore;google-authstays optional and is supplied by each plugin's[google-cloud]extra.genkit.plugin_api.GoogleCloudsogenkit_openai.GoogleCloud is genkit_anthropic.GoogleCloud(avoiding import-shadowingTypeErrors when both plugins are used in one app).genkit.plugin_api:resolve_google_cloud_project(config)— checksconfig.project, thenGCLOUD_PROJECT, thenGOOGLE_CLOUD_PROJECT, elseNone(ADC fallback).resolve_google_cloud_location(config, *, default)— checksconfig.location, thenGOOGLE_CLOUD_LOCATION, then the plugin's own default ('global'for Claude,'us-central1'for Model Garden open models).require_google_auth(*, caller, extra)— fails fast at plugin construction withImportErrornaming theuv add '<extra>'command whengoogle-authisn't installed.load_google_adc(*, caller, scopes=...)— loads and refreshes ADC withcloud-platformscope, mapping missing or stale credentials toGenkitError(status='FAILED_PRECONDITION')with thegcloud auth application-default loginfix.GoogleAdcToken(credentials, *, caller)— async bearer-token callable that refreshes expired credentials in a thread and maps refresh failures toFAILED_PRECONDITION.packages/genkit/pyproject.toml): ignores lazy optionalgoogleimport (DEP001/DEP003).packages/genkit/tests/genkit/core/google_cloud_test.py): self-contained tests covering export boundaries (genkit.plugin_apionly, not top-levelgenkit), dataclass immutability, project/location precedence, missing extra error, ADC load/refresh error mapping, andGoogleAdcTokencaching/refresh (runs withoutgoogle-authinstalled).Verification
uv run --no-sync pytest packages/genkit/tests/genkit/core/google_cloud_test.py packages/genkit/tests/genkit/docs_exports_test.py packages/genkit/tests/genkit/core/public_types_runtime_test.py— 33 passeduv run --no-sync ruff format --check --preview .,ruff check --preview .,ty check .,pyrefly checkon changed files — passedcd packages/genkit && uv run --no-sync deptry src— passedscripts/check_consistency.pyanduv lock --check— passedFollow-ups
Anthropic(backend=GoogleCloud())) and feat(py): serve Model Garden's OpenAI-compatible models via OpenAICompatible(backend=GoogleCloud()) #188 (OpenAICompatible(backend=GoogleCloud())).Breaking changes
None.