Skip to main content

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_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_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_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:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

genkit_google_genai-0.8.0.tar.gz (87.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

genkit_google_genai-0.8.0-py3-none-any.whl (73.3 kB view details)

Uploaded Python 3

File details

Details for the file genkit_google_genai-0.8.0.tar.gz.

File metadata

  • Download URL: genkit_google_genai-0.8.0.tar.gz
  • Upload date:
  • Size: 87.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for genkit_google_genai-0.8.0.tar.gz
Algorithm Hash digest
SHA256 d5c688ce46860a0ded81f11991efcc60702fdc9ef14348ad2392e4fb7f0dda60
MD5 5b5dca4462670e5265b7c4c2ddb0254f
BLAKE2b-256 74166132203cba14e77a63384693e4255b2661323c189e5eea5a85ce0aae2a91

See more details on using hashes here.

Provenance

The following attestation bundles were made for genkit_google_genai-0.8.0.tar.gz:

Publisher: publish_python.yml on genkit-ai/genkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file genkit_google_genai-0.8.0-py3-none-any.whl.

File metadata

File hashes

Hashes for genkit_google_genai-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 718bbfb3bc4bef40807b61bfafdea03acb75521aa5550eb9b48482092e572cdc
MD5 3adec5ed186b84eae7d1736b6b9e7cb4
BLAKE2b-256 87f4fa3e4b879a0b118a070b3c5104eb1fc42e77c721ebd50a829adbe910e877

See more details on using hashes here.

Provenance

The following attestation bundles were made for genkit_google_genai-0.8.0-py3-none-any.whl:

Publisher: publish_python.yml on genkit-ai/genkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page