Repository navigation
feat(py): serve Model Garden's OpenAI-compatible models via OpenAICompatible(backend=GoogleCloud()) - #188
feat(py): serve Model Garden's OpenAI-compatible models via OpenAICompatible(backend=GoogleCloud())#188huangjeff5 wants to merge 1 commit into
Conversation
| self, | ||
| *, | ||
| backend: GoogleCloud, | ||
| name: Literal['modelgarden'] | None = None, |
There was a problem hiding this comment.
Should allow things other than modelgarden
There was a problem hiding this comment.
Done — relaxed the backend: GoogleCloud overload to name: str | None = None, defaulting to 'modelgarden' when omitted while accepting any valid single-segment namespace (so multiple regions/projects can run side by side).
| - `OpenAIConfig` is the config for every model. A server may ignore fields it | ||
| doesn't support, or reject them. | ||
|
|
||
| ### Model Garden on Google Cloud |
There was a problem hiding this comment.
Should explain OpenAiCompatible's main use case first and explain this after
There was a problem hiding this comment.
Restored OpenAICompatible's class docstring so OpenRouter + local keyless server come first and Model Garden follows after, and reframed this section's opening as a built-in backend on top of OpenAICompatible. Note: in the full README, ## Any OpenAI-compatible server (from base PR #187, lines 60–106) already precedes ### Model Garden on Google Cloud — it was just hidden in #188's stacked diff.
|
|
||
|
|
||
| @dataclass(frozen=True, kw_only=True) | ||
| class GoogleCloud: |
There was a problem hiding this comment.
Is this shared with Anthropic plugin? Look for a way to share this across plugins
There was a problem hiding this comment.
Keeping GoogleCloud and the ADC helpers local to genkit-openai rather than expanding genkit core exports — only genkit-openai and genkit-anthropic need this shape.
0f669fe to
9680bcb
Compare
…patible(backend=GoogleCloud())
9680bcb to
92c7b63
Compare
OpenAICompatible(backend=GoogleCloud(...))serves Model Garden's OpenAI-compatible models (Llama, Mistral and others) from Google Cloud, billed to your project and authenticated with application default credentials. The backend builds the endpoint and handles the token, so there's nobase_url, no key and no token code.garden.model(id)gives the ref for any of these models.Stacked on #187. Review and merge that first.
This is the replacement #185 needs for Llama and the other open models when
genkit-vertexaiis removed. Refs default tomodelgarden/<publisher>/<model>, as they were inModelGarden, so moving over is a constructor change only — and you can pass a customname=when you want another namespace (for example, to run multiple regions or projects side by side).Changes
backend=onOpenAICompatible, and a new exportedGoogleCloud(project=None, location=None). The endpoint ishttps://{location}-aiplatform.googleapis.com/v1beta1/projects/{project}/locations/{location}/endpoints/openapi, the same oneModelGardenuses.globalgets the unregioned host.base_url=overrides it, for example for Private Service Connect, and auth stays Google's.project=, thenGCLOUD_PROJECT, thenGOOGLE_CLOUD_PROJECT, then the credentials' project.location=, thenGOOGLE_CLOUD_LOCATION, thenus-central1(ModelGarden's default; most open models are regional).namerule.nameis still required, as in JS and Go.GoogleCloud:nameis optional and defaults to'modelgarden'; any other valid single-segment name (non-empty, no'/') is accepted so multiple regions or projects can coexist in one app.FAILED_PRECONDITIONwith thegcloudcommand that fixes it.FAILED_PRECONDITIONnaming three ways to set one.FAILED_PRECONDITION, before ADC is touched, because every call bills the project.api_key=together withGoogleCloudraisesValueErrorat setup./models, so no request goes out. Any id resolves when called.google-cloudextra →google-auth[requests]>=2.14.1, the same bound asgenkit-vertexai. Without it, the constructor raisesImportErrorwith theuv addcommand.OpenAICompatible's main use case, with first-time setup, defaults, customname=, and the Claude pointer (Anthropic(backend=GoogleCloud())).Decisions
.model(), config) is theOpenAICompatiblepath from feat(py): add OpenAICompatible for any OpenAI-compatible server, matching JS and Go #187. This mirrorsAnthropic(backend=GoogleCloud()).GoogleCloudlocal to each plugin, not exported fromgenkitcore: Onlygenkit-openaiandgenkit-anthropicneed this shape, so duplicating the small config + ADC module is cheaper than expandinggenkitcore's public API surface.modelgardendefault name, customname=allowed: Llama users' refs don't change when leavinggenkit-vertexai, while passingname=lets apps register multiple Google Cloud regions, projects, or PSC endpoints side by side.us-central1by default, notglobal: The open models are mostly regional, andModelGardendefaulted tous-central1. This differs fromgenkit-anthropic'sGoogleCloud, which defaults toglobalbecause every Claude model has global quota.genkit-vertexai's Llama 3.1 and 3.2 entries) is stale. Any id resolves, and a curated list can come later without an API change.asyncio.Lockwould bind to one event loop, and the plugin's clients are per-loop.Verification
packages/genkit-openai: 648 passed, includingopenai_compatible_google_cloud_test.pycovering custom names, multi-region/project coexistence, invalid names, endpoint URLs, ADC loading/caching/retry, token refresh/errors, and missing extra error.ruff format --check --preview .,ruff check --preview .,ty check .,pyrefly checkon changed files,scripts/check_consistency.py, anduv lock --checkall pass.Breaking changes
None.
backendis optional, andOpenAICompatiblewithout it behaves as in #187.