Skip to main content

Dagster integration for Google Cloud Vertex AI

Project description

dagster-vertexai

A dagster module that provides integration with Google Cloud Vertex AI.

Installation

The dagster_vertexai module is available as a PyPI package - install with your preferred python environment manager (We recommend uv).

source .venv/bin/activate
uv pip install dagster-vertexai

Example Usage

In addition to wrapping the Vertex AI GenerativeModel class (get_model/get_model_for_asset methods), this resource logs the usage of the Vertex AI API to the asset metadata (both number of calls, and tokens). This is achieved by wrapping the GenerativeModel.generate_content method.

Note that the usage will only be logged to the asset metadata from an Asset context - not from an Op context. Also note that only the synchronous API usage metadata will be automatically logged - not the streaming or batching API.

from dagster import AssetExecutionContext, Definitions, EnvVar, asset
from dagster_vertexai import VertexAIResource


@asset(compute_kind="vertexai")
def vertexai_asset(context: AssetExecutionContext, vertexai: VertexAIResource):
    with vertexai.get_model(context) as model:
        response = model.generate_content(
            "Generate a short sentence on tests"
        )
        return response.text

defs = Definitions(
    assets=[vertexai_asset],
    resources={
        "vertexai": VertexAIResource(
            project_id=EnvVar("VERTEX_AI_PROJECT_ID"),
            location=EnvVar("VERTEX_AI_LOCATION"),
            generative_model_name="gemini-1.5-flash-001"
        ),
    },
)

Configuration

The VertexAIResource supports the following configuration options:

  • project_id: Your Google Cloud project ID
  • location: The Google Cloud region (e.g., "us-central1")
  • generative_model_name: The name of the generative model (e.g., "gemini-1.5-flash-001")
  • google_credentials (optional): JSON string of service account credentials. If not provided, uses Application Default Credentials
  • api_endpoint (optional): Custom API endpoint URL

Authentication

Authentication is handled via Application Default Credentials (ADC) by default. To authenticate:

gcloud auth application-default login

Alternatively, you can provide service account credentials via the google_credentials parameter.

Multi-Asset Usage

For multi-assets, use the get_model_for_asset method to specify which asset the usage metadata should be logged to:

from dagster import AssetExecutionContext, AssetKey, AssetSpec, MaterializeResult, multi_asset

@multi_asset(
    specs=[AssetSpec("summary"), AssetSpec("analysis")]
)
def vertexai_multi_asset(context: AssetExecutionContext, vertexai: VertexAIResource):
    # Generate summary
    with vertexai.get_model_for_asset(context, AssetKey("summary")) as model:
        summary = model.generate_content("Summarize this data...")
    
    # Generate analysis  
    with vertexai.get_model_for_asset(context, AssetKey("analysis")) as model:
        analysis = model.generate_content("Analyze this data...")
    
    yield MaterializeResult(asset_key="summary", metadata={"content": summary.text})
    yield MaterializeResult(asset_key="analysis", metadata={"content": analysis.text})

Development

The Makefile provides the tools required to test and lint your local installation

make test
make ruff
make check

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

dagster_vertexai-0.0.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

dagster_vertexai-0.0.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file dagster_vertexai-0.0.1.tar.gz.

File metadata

  • Download URL: dagster_vertexai-0.0.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.15

File hashes

Hashes for dagster_vertexai-0.0.1.tar.gz
Algorithm Hash digest
SHA256 cb4cb9e88ec0cdddfa0d0a4f5907ff1fbaf512eb9358406b39b90487e9b2075e
MD5 f77c7baf73a1374bd44937699db90d52
BLAKE2b-256 46e7870f12a482c208255091dd49cd9979cee32ed08b4061f06ffe883d7b7890

See more details on using hashes here.

File details

Details for the file dagster_vertexai-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for dagster_vertexai-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3e944d31fd9ba56d355fa352621004068fa7257b0810eb19c085d4ae064ecce8
MD5 077e151a29bcfdd042d22bcb02472be6
BLAKE2b-256 2f308a8fe777a54f71ab18b77df434874aee56bb73da15803fa931952878e9d9

See more details on using hashes here.

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