Genkit Google GenAI Plugin
Project description
Google GenAI Plugin
This Genkit plugin provides a unified interface for Google AI (Gemini) and Vertex AI models, embedding, and other services.
Setup environment
uv venv
source .venv/bin/activate
pip install genkit-plugins-google-genai
Configuration
Google AI (AI Studio)
To use Google AI models, obtain an API key from Google AI Studio and set it in your environment:
export GEMINI_API_KEY='<your-api-key>'
Vertex AI (Google Cloud)
To use Vertex AI models, ensure you have a Google Cloud project and Application Default Credentials (ADC) set up:
gcloud auth application-default login
Features
Dynamic Models
The plugin automatically discovers available models from the API upon initialization. You can use any model name supported by the API (e.g., googleai/gemini-2.0-flash-exp, vertexai/gemini-1.5-pro).
Dynamic Configuration
New or experimental parameters can be passed flexibly using model_validate to bypass strict schema checks:
from genkit.plugins.google_genai import GeminiConfigSchema
config = GeminiConfigSchema.model_validate({
'temperature': 1.0,
'response_modalities': ['TEXT', 'IMAGE'],
})
Vertex AI Rerankers
The VertexAI plugin provides semantic rerankers for improving RAG quality by re-scoring documents based on relevance:
from genkit import Genkit
from genkit.plugins.google_genai import VertexAI
ai = Genkit(plugins=[VertexAI(project='my-project')])
# Rerank documents after retrieval
ranked_docs = await ai.rerank(
reranker='vertexai/semantic-ranker-default@latest',
query='What is machine learning?',
documents=retrieved_docs,
options={'top_n': 5},
)
Supported Models:
| Model | Description |
|---|---|
semantic-ranker-default@latest |
Latest default semantic ranker |
semantic-ranker-default-004 |
Semantic ranker version 004 |
semantic-ranker-fast-004 |
Fast variant (lower latency) |
Vertex AI Evaluators
Built-in evaluators for assessing model output quality. Evaluators are automatically registered when using the VertexAI plugin and are accessed via ai.evaluate():
from genkit import Genkit
from genkit._core.typing import BaseDataPoint
from genkit.plugins.google_genai import VertexAI
ai = Genkit(plugins=[VertexAI(project='my-project')])
# Prepare test dataset
dataset = [
BaseDataPoint(
input='Write about AI.',
output='AI is transforming industries through intelligent automation.',
),
]
# Evaluate fluency (scores 1-5)
results = await ai.evaluate(
evaluator='vertexai/fluency',
dataset=dataset,
)
for result in results.root:
print(f'Score: {result.evaluation.score}')
Supported Metrics:
| Metric | Description |
|---|---|
BLEU |
Translation quality (compare to reference) |
ROUGE |
Summarization quality |
FLUENCY |
Language mastery and readability |
SAFETY |
Harmful/inappropriate content detection |
GROUNDEDNESS |
Hallucination detection |
SUMMARIZATION_QUALITY |
Overall summarization ability |
Examples
For comprehensive usage examples, see:
py/samples/google-genai-media/README.md- Speech, image, and video generationpy/samples/gemini-code-execution/README.md- Gemini code executionpy/samples/gemini-context-caching/README.md- Context caching for large promptspy/samples/vertexai-imagen/README.md- Vertex AI Imagen generation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file genkit_plugin_google_genai-0.5.2.tar.gz.
File metadata
- Download URL: genkit_plugin_google_genai-0.5.2.tar.gz
- Upload date:
- Size: 64.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
745ecafce67f386a5dcc619c9d8a4c46695f8c5d3b64e11a4ca9f54c582e140c
|
|
| MD5 |
af2a12f3672711d1dfe788207f530f88
|
|
| BLAKE2b-256 |
16909a9a3ec19abb0b60cdabdc11669dc29e6a2922df8fcbaf294378e0f97e6d
|
Provenance
The following attestation bundles were made for genkit_plugin_google_genai-0.5.2.tar.gz:
Publisher:
publish_python.yml on genkit-ai/genkit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
genkit_plugin_google_genai-0.5.2.tar.gz -
Subject digest:
745ecafce67f386a5dcc619c9d8a4c46695f8c5d3b64e11a4ca9f54c582e140c - Sigstore transparency entry: 1200140515
- Sigstore integration time:
-
Permalink:
genkit-ai/genkit@45f19aafbe502cb4bb8569416e6aed6533d97bc2 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/genkit-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_python.yml@45f19aafbe502cb4bb8569416e6aed6533d97bc2 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file genkit_plugin_google_genai-0.5.2-py3-none-any.whl.
File metadata
- Download URL: genkit_plugin_google_genai-0.5.2-py3-none-any.whl
- Upload date:
- Size: 64.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05191fd7c7d3973f34a240e2c7f1e4885e088a577a00e968937bb04d1f4b5b2f
|
|
| MD5 |
256ed6734fb970b2f31401805a8f2bf8
|
|
| BLAKE2b-256 |
c7f2774995a8cfc2e3ab49066912d97c46be9f814b38f73123555418b7e43376
|
Provenance
The following attestation bundles were made for genkit_plugin_google_genai-0.5.2-py3-none-any.whl:
Publisher:
publish_python.yml on genkit-ai/genkit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
genkit_plugin_google_genai-0.5.2-py3-none-any.whl -
Subject digest:
05191fd7c7d3973f34a240e2c7f1e4885e088a577a00e968937bb04d1f4b5b2f - Sigstore transparency entry: 1200140583
- Sigstore integration time:
-
Permalink:
genkit-ai/genkit@45f19aafbe502cb4bb8569416e6aed6533d97bc2 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/genkit-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_python.yml@45f19aafbe502cb4bb8569416e6aed6533d97bc2 -
Trigger Event:
workflow_dispatch
-
Statement type: