Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 80 additions & 3 deletions packages/genkit-vertexai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

Integrate Genkit with Google Cloud Vertex AI Model Garden.

> **Deprecated: genkit-vertexai will be removed in the next release.**
>
> - **Claude**: move to the Anthropic plugin on Google Cloud. It's the same
> models, billed to the same project. See
> [Moving Claude to the Anthropic plugin](#moving-claude-to-the-anthropic-plugin).
> - **Llama, Mistral and other OpenAI-compatible Model Garden models**: move
> to `OpenAICompatible(backend=GoogleCloud())` from
> `genkit-openai[google-cloud]`. Refs stay `modelgarden/<publisher>/<model>`.
> See [Moving Llama and Mistral](#moving-llama-and-mistral).
>
> Everything keeps working in this release. `ModelGarden(...)` raises a
> `FutureWarning`. This package now requires the matching `genkit` minor
> version, so upgrading `genkit` past this release means removing
> `genkit-vertexai` first.

> **Building with a coding agent? Install the Genkit Python skill first.**
>
> ```bash
Expand All @@ -17,9 +32,8 @@ Integrate Genkit with Google Cloud Vertex AI Model Garden.
Install the extra for the Model Garden publishers you call:

```bash
uv add 'genkit-vertexai[anthropic]' # Claude
uv add 'genkit-vertexai[openai]' # Llama, Mistral, and other OpenAI-compatible models
uv add 'genkit-vertexai[anthropic,openai]' # both
uv add 'genkit-vertexai[anthropic]' # Claude
```

The package without an extra serves no models. Calling a model without its
Expand All @@ -38,7 +52,7 @@ ai = Genkit(

async def main() -> None:
res = await ai.generate(
model='modelgarden/anthropic/claude-sonnet-4-6',
model='modelgarden/meta/llama-3.1-405b-instruct-maas',
prompt='Explain recursion in 10 words.',
)
print(res.text)
Expand All @@ -57,3 +71,66 @@ Every call runs on those Google Cloud credentials. A per-request key in
`context={'secrets': {'api_key': ...}}` fails with `INVALID_ARGUMENT` before
any request is sent, so a tenant's key never runs on the app's account. Other
entries in `context.secrets` are ignored.

## Moving Claude to the Anthropic plugin

Claude on Google Cloud now runs through `genkit-anthropic`, billed to the same
project with the same credentials. You get typed refs and `AnthropicConfig`,
and `.prompt` files that also work on the Anthropic API.

```bash
uv add 'genkit-anthropic[google-cloud]'
```

```python
from genkit import Genkit
from genkit_anthropic import Anthropic, GoogleCloud

# Before
ai = Genkit(plugins=[ModelGarden(project='bistro-prod', location='global')])
await ai.generate(model='modelgarden/anthropic/claude-sonnet-5-5', prompt='Suggest a dish.')

# After
ai = Genkit(plugins=[Anthropic(backend=GoogleCloud(project='bistro-prod', location='global'))])
await ai.generate(model=Anthropic.claude('claude-sonnet-5-5'), prompt='Suggest a dish.')
```

- Model names drop the `modelgarden/anthropic/` prefix and any `@date`
suffix: `modelgarden/anthropic/claude-sonnet-4-5@20250929` becomes
`Anthropic.claude('claude-sonnet-4-5')`.
- `project` and `location` mean the same thing in `GoogleCloud(...)` and
default the same way. `model_locations` has no equivalent: an app uses one
location for Claude. The default, `global`, serves every Claude model.
- Config is unchanged: Model Garden Claude already took `AnthropicConfig`.

See the [genkit-anthropic README](../genkit-anthropic/README.md#claude-on-google-cloud)
for first-time Google Cloud setup.

## Moving Llama and Mistral

Model Garden's OpenAI-compatible models move to `genkit-openai`, with the same
project, credentials and refs.

```bash
uv add 'genkit-openai[google-cloud]'
```

```python
from genkit import Genkit
from genkit_openai import GoogleCloud, OpenAICompatible

# Before
ai = Genkit(plugins=[ModelGarden(project='bistro-prod', location='us-central1')])
await ai.generate(model='modelgarden/meta/llama-3.3-70b-instruct-maas', prompt='Suggest a dish.')

# After: the same ref
garden = OpenAICompatible(backend=GoogleCloud(project='bistro-prod', location='us-central1'))
ai = Genkit(plugins=[garden])
await ai.generate(model='modelgarden/meta/llama-3.3-70b-instruct-maas', prompt='Suggest a dish.')
```

- `location` defaults to `us-central1` in both. To serve models from a second
region or project in the same app, register another `OpenAICompatible` with
its own `name=` (for example `OpenAICompatible(name='garden-eu', backend=GoogleCloud(location='europe-west4'))`).
- Config is unchanged: Model Garden's OpenAI-compatible models already took
`OpenAIConfig`.
4 changes: 2 additions & 2 deletions packages/genkit-vertexai/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ classifiers = [
"License :: OSI Approved :: Apache Software License",
]
dependencies = [
"genkit>=0.14.0,<2",
"genkit>=0.14.0,<0.15",
"google-auth[requests]>=2.14.1",
]
description = "Vertex AI and Model Garden on Genkit"
description = "Deprecated, removed in the next release. Use genkit-anthropic[google-cloud] for Claude and genkit-openai[google-cloud] for other Model Garden models."
keywords = [
"genkit",
"vertex-ai",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import asyncio
import os
import warnings
from collections.abc import Awaitable, Callable, Iterator
from contextlib import contextmanager
from dataclasses import dataclass
Expand All @@ -48,6 +49,19 @@
MODELGARDEN_PLUGIN_NAME = 'modelgarden'


# FutureWarning, not DeprecationWarning: Python's default filters hide
# DeprecationWarning outside __main__ (PEP 565), which would silence it in web
# servers and imported modules. Same choice as the evaluators deprecation.
DEPRECATION_MESSAGE = (
'genkit-vertexai is deprecated and will be removed in the next release. '
"For Claude, use the Anthropic plugin on Google Cloud: uv add 'genkit-anthropic[google-cloud]', "
"then Anthropic(backend=GoogleCloud()) and model=Anthropic.claude('claude-sonnet-5-5') "
"in place of model='modelgarden/anthropic/claude-sonnet-5-5'. "
"For Llama, Mistral and the other OpenAI-compatible models: uv add 'genkit-openai[google-cloud]', "
'then OpenAICompatible(backend=GoogleCloud()); refs stay modelgarden/<publisher>/<model>.'
)


@dataclass(frozen=True)
class _Extra:
"""An optional publisher dependency of genkit-vertexai.
Expand Down Expand Up @@ -208,6 +222,11 @@ class ModelGarden(Plugin):
enabling the use of Vertex AI models and services within the Genkit
framework. It handles initialization of the Model Garden client and
registration of model actions.

Deprecated: genkit-vertexai will be removed in the next release. For
Claude, use ``Anthropic(backend=GoogleCloud())`` from
``genkit-anthropic[google-cloud]``. Constructing ``ModelGarden`` raises a
``FutureWarning``; every model keeps working until the removal.
"""

name = MODELGARDEN_PLUGIN_NAME
Expand All @@ -233,6 +252,7 @@ def __init__(
Google Cloud regions. This overrides the default `location` for the
specified models.
"""
warnings.warn(DEPRECATION_MESSAGE, FutureWarning, stacklevel=2)
self.project = (
project if project is not None else os.getenv(const.GCLOUD_PROJECT) or os.getenv('GOOGLE_CLOUD_PROJECT')
)
Expand Down
17 changes: 16 additions & 1 deletion packages/genkit-vertexai/tests/model_garden/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
#
# SPDX-License-Identifier: Apache-2.0

"""A fake Vertex Claude endpoint shared by the Model Garden tests."""
"""A fake Vertex Claude endpoint shared by the Model Garden tests, and the deprecation filter."""

import pathlib
from collections.abc import Iterator
from typing import Any
from unittest.mock import patch
Expand Down Expand Up @@ -59,3 +60,17 @@ def client(**kwargs: Any) -> AsyncAnthropicVertex:

with patch('genkit_vertexai._model_garden._anthropic.AsyncAnthropicVertex', client):
yield fake.requests


_HERE = pathlib.Path(__file__).parent
_DEPRECATION_FILTER = pytest.mark.filterwarnings('ignore:genkit-vertexai is deprecated:FutureWarning')


def pytest_collection_modifyitems(items: list[pytest.Item]) -> None:
"""Every ModelGarden(...) warns; the warning is pinned by its own test, so it's filtered elsewhere here.

This hook sees the whole session's items, so it only marks the ones in this directory.
"""
for item in items:
if _HERE in pathlib.Path(str(item.path)).parents:
item.add_marker(_DEPRECATION_FILTER)
25 changes: 25 additions & 0 deletions packages/genkit-vertexai/tests/model_garden/model_garden_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,3 +601,28 @@ async def test_model_garden_without_models_still_resolves_any_model() -> None:

assert response.text == 'hello from mistral'
assert client.chat.completions.create.call_args.kwargs['model'] == 'mistralai/mistral-small-2503'


def test_model_garden_warns_that_the_package_is_deprecated() -> None:
"""Constructing ModelGarden raises a FutureWarning naming the Claude replacement and the removal."""
with pytest.warns(FutureWarning) as record:
ModelGarden(project='p', location='global')

message = str(record[0].message)
assert 'genkit-vertexai is deprecated and will be removed in the next release' in message
assert "uv add 'genkit-anthropic[google-cloud]'" in message
assert 'Anthropic(backend=GoogleCloud())' in message
assert "uv add 'genkit-openai[google-cloud]'" in message
assert 'OpenAICompatible(backend=GoogleCloud())' in message
assert 'refs stay modelgarden/<publisher>/<model>' in message
# Attributed to the caller's line, not to genkit-vertexai.
assert record[0].filename == __file__


@pytest.mark.asyncio
async def test_model_garden_models_keep_working_while_deprecated() -> None:
"""Deprecated isn't removed: Claude and Llama still resolve this release."""
ai = Genkit(plugins=[ModelGarden(project='p', location='global')])

assert await ai.lookup_model(CLAUDE) is not None
assert await ai.lookup_model(LLAMA) is not None
4 changes: 2 additions & 2 deletions packages/genkit/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ middleware = ["genkit-middleware>=0.14.0,<2"]
otel = ["genkit-otel>=0.14.0,<2"]
ollama = ["genkit-ollama>=0.14.0,<2"]
openai = ["genkit-openai>=0.14.0,<2"]
vertex-ai = ["genkit-vertexai[anthropic,openai]>=0.14.0,<2"]
vertexai = ["genkit-vertexai[anthropic,openai]>=0.14.0,<2"]
vertex-ai = ["genkit-vertexai[anthropic,openai]>=0.14.0,<0.15"]
vertexai = ["genkit-vertexai[anthropic,openai]>=0.14.0,<0.15"]

[project.urls]
"Bug Tracker" = "https://github.com/genkit-ai/genkit-python/issues"
Expand Down
4 changes: 3 additions & 1 deletion scripts/check_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@

PY_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
EXPECTED_PYTHON = '>=3.10'
ZERO_X_ONLY_PACKAGES: frozenset[str] = frozenset({'genkit-evaluators'})
# Deprecated packages capped at the next minor while on 0.x, so dropping them
# in a later 0.x release doesn't leave an old copy installable next to a newer genkit.
ZERO_X_ONLY_PACKAGES: frozenset[str] = frozenset({'genkit-evaluators', 'genkit-vertexai'})

_INTRA_REPO_NAME_RE = re.compile(r'^\s*(genkit(?:-[a-z0-9-]+)?)\b')
_EXACT_PIN_RE = re.compile(r'^(genkit(?:-[a-z0-9-]+)?)(?:\[[a-z0-9,_-]+\])?==([^,;\s]+)$')
Expand Down
Loading
Loading