chore: import upstream snapshot with attribution
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Has been cancelled
Test and Publish Multi-arch Docker Image / test (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Has been cancelled
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Has been cancelled
Validate Renovate Config / Validate Renovate Configuration (push) Has been cancelled
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Has been cancelled
Test and Publish Multi-arch Docker Image / test (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Has been cancelled
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Has been cancelled
Validate Renovate Config / Validate Renovate Configuration (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
# google-imagen (Google Imagen)
|
||||
|
||||
This example demonstrates Google image generation models, including both Imagen and Gemini native image generation.
|
||||
|
||||
You can run this example with:
|
||||
|
||||
```bash
|
||||
npx promptfoo@latest init --example google-imagen
|
||||
cd google-imagen
|
||||
```
|
||||
|
||||
## Prerequisites
|
||||
|
||||
You can use Imagen models through either Google AI Studio or Vertex AI:
|
||||
|
||||
### Option 1: Google AI Studio (Quick Start, Limited Features)
|
||||
|
||||
- Get an API key from [Google AI Studio](https://aistudio.google.com/apikey)
|
||||
- **Supports**: Imagen 4 models only
|
||||
- **Limitations**: No `seed` or `addWatermark` parameters
|
||||
|
||||
### Option 2: Vertex AI (Full Features)
|
||||
|
||||
- Google Cloud project with billing enabled
|
||||
- Vertex AI API enabled
|
||||
- Authentication via `gcloud auth application-default login`
|
||||
- **Supports**: All Imagen models and all parameters
|
||||
|
||||
## Setup
|
||||
|
||||
### For Google AI Studio:
|
||||
|
||||
```bash
|
||||
# Set your API key (Unix/Linux/macOS)
|
||||
export GOOGLE_API_KEY=your-api-key
|
||||
|
||||
# For Windows Command Prompt:
|
||||
# set GOOGLE_API_KEY=your-api-key
|
||||
|
||||
# For Windows PowerShell:
|
||||
# $env:GOOGLE_API_KEY="your-api-key"
|
||||
```
|
||||
|
||||
### For Vertex AI:
|
||||
|
||||
```bash
|
||||
# Enable Vertex AI API
|
||||
gcloud services enable aiplatform.googleapis.com
|
||||
|
||||
# Authenticate
|
||||
gcloud auth application-default login
|
||||
|
||||
# Set project ID (Unix/Linux/macOS)
|
||||
export GOOGLE_PROJECT_ID=your-project-id
|
||||
|
||||
# For Windows Command Prompt:
|
||||
# set GOOGLE_PROJECT_ID=your-project-id
|
||||
|
||||
# For Windows PowerShell:
|
||||
# $env:GOOGLE_PROJECT_ID="your-project-id"
|
||||
```
|
||||
|
||||
## Environment Variables
|
||||
|
||||
- `GOOGLE_API_KEY` - Google AI Studio API key (Option 1)
|
||||
- `GOOGLE_PROJECT_ID` - Your Google Cloud project ID (Option 2)
|
||||
|
||||
## Available Models
|
||||
|
||||
### Imagen Models (use `google:image:` prefix)
|
||||
|
||||
- `imagen-4.0-ultra-generate-001` - Ultra quality ($0.06/image)
|
||||
- `imagen-4.0-generate-001` - Standard quality ($0.04/image)
|
||||
- `imagen-4.0-fast-generate-001` - Fast generation ($0.02/image)
|
||||
- `imagen-3.0-generate-002` - Imagen 3.0 ($0.04/image)
|
||||
|
||||
Google has deprecated the Imagen 4 models with an August 17, 2026 shutdown and recommends `gemini-3.1-flash-image` as the replacement. The older `imagen-4.0-*-preview-06-06` ids are already shut down.
|
||||
|
||||
### Gemini Native Image Generation
|
||||
|
||||
- `google:gemini-3.1-flash-lite-image` - Gemini 3.1 Flash-Lite (Nano Banana 2 Lite) for the fastest, lowest-cost image generation (~$0.034/image at 1K; 1K only)
|
||||
- `google:gemini-3.1-flash-image` - Gemini 3.1 Flash (Nano Banana 2) with native image generation (~$0.067/image at 1K)
|
||||
- `google:gemini-3-pro-image` - Gemini 3 Pro (Nano Banana Pro) with native image generation (~$0.134/image at 1K/2K)
|
||||
- `google:gemini-2.5-flash-image` - Gemini 2.5 Flash (Nano Banana) with image generation (~$0.039/image)
|
||||
|
||||
Use the GA ids above; Google shut down the `gemini-3.1-flash-image-preview` and `gemini-3-pro-image-preview` aliases on June 25, 2026. Nano Banana 2 Lite never had a `-preview` alias.
|
||||
|
||||
## Running the Example
|
||||
|
||||
```bash
|
||||
npx promptfoo@latest eval
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- Imagen models are available through both **Google AI Studio** and **Vertex AI**
|
||||
- **Google AI Studio**:
|
||||
- Uses API key authentication (quick start)
|
||||
- Only supports Imagen 4 models (4.0 preview models)
|
||||
- Limited parameter support:
|
||||
- No `seed` or `addWatermark` parameters
|
||||
- Only `block_low_and_above` safety filter level
|
||||
- **Vertex AI**:
|
||||
- Requires authentication via `gcloud auth application-default login`
|
||||
- Supports all Imagen models (both 3.0 and 4.0)
|
||||
- Full parameter support:
|
||||
- All safety filter levels (`block_most`, `block_some`, `block_few`, `block_fewest`)
|
||||
- `seed` for deterministic generation
|
||||
- `addWatermark` control
|
||||
- You must provide a Google Cloud project ID either via:
|
||||
- `GOOGLE_PROJECT_ID` environment variable
|
||||
- `projectId` in the provider config
|
||||
- Seed and watermark parameters are mutually exclusive (Vertex AI only)
|
||||
|
||||
## Advanced Configuration
|
||||
|
||||
See `promptfooconfig-advanced.yaml` for examples of platform-specific configurations that take advantage of each platform's unique capabilities.
|
||||
|
||||
## Gemini Native Image Generation
|
||||
|
||||
Gemini models can generate images natively using the `generateContent` API with `responseModalities` set to include images. This is different from Imagen which uses a dedicated image generation endpoint.
|
||||
|
||||
See `promptfooconfig-gemini.yaml` for Gemini native image generation examples.
|
||||
See `promptfooconfig-gemini-grounding.yaml` for Google Search-grounded Gemini image generation.
|
||||
|
||||
Key differences from Imagen:
|
||||
|
||||
- Uses the same `google:` provider namespace as Gemini chat (models with `-image` in the name automatically enable image generation)
|
||||
- Supports additional aspect ratios: `1:4`, `1:8`, `2:3`, `3:2`, `4:1`, `4:5`, `5:4`, `8:1`, `21:9`
|
||||
- Supports image resolution: `512px` (Gemini 3.1), `1K`, `2K`, `4K`
|
||||
- Can return both text and images in the same response
|
||||
- Uses the same authentication as Gemini chat models
|
||||
- Supports Google Search grounding via `tools: [{ googleSearch: {} }]`
|
||||
@@ -0,0 +1,44 @@
|
||||
# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
|
||||
description: Advanced Imagen configuration showing platform-specific settings
|
||||
|
||||
prompts:
|
||||
- 'Create a {{quality}} image of {{subject}} with {{style}} aesthetic'
|
||||
|
||||
providers:
|
||||
# Google AI Studio configuration (API key authentication)
|
||||
- id: google:image:imagen-4.0-generate-001
|
||||
label: Imagen 4.0 (Google AI Studio)
|
||||
config:
|
||||
aspectRatio: '16:9'
|
||||
safetyFilterLevel: 'block_low_and_above' # Only value supported by Google AI Studio
|
||||
# Note: seed and addWatermark are not supported in Google AI Studio
|
||||
|
||||
# Vertex AI configuration (OAuth authentication)
|
||||
- id: google:image:imagen-4.0-generate-001
|
||||
label: Imagen 4.0 (Vertex AI)
|
||||
config:
|
||||
projectId: 'your-project-id' # Forces Vertex AI usage
|
||||
aspectRatio: '16:9'
|
||||
safetyFilterLevel: 'block_some' # Vertex AI supports all safety levels
|
||||
seed: 42 # Deterministic generation
|
||||
addWatermark: false # Disable watermark (incompatible with seed)
|
||||
|
||||
# Imagen 3.0 - Only available through Vertex AI
|
||||
- id: google:image:imagen-3.0-generate-002
|
||||
label: Imagen 3.0 (Vertex AI only)
|
||||
config:
|
||||
projectId: 'your-project-id'
|
||||
aspectRatio: '1:1'
|
||||
safetyFilterLevel: 'block_fewest'
|
||||
personGeneration: 'allow_adult'
|
||||
|
||||
tests:
|
||||
- vars:
|
||||
quality: 'photorealistic'
|
||||
subject: 'a serene mountain landscape'
|
||||
style: 'golden hour photography'
|
||||
assert:
|
||||
- type: javascript
|
||||
value: |
|
||||
// Check if the output contains a valid image data URL
|
||||
return output.includes('
|
||||
@@ -0,0 +1,24 @@
|
||||
# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
|
||||
description: Gemini image generation with search grounding
|
||||
|
||||
prompts:
|
||||
- 'Create a travel poster for {{city}} using real landmarks and current points of interest'
|
||||
|
||||
providers:
|
||||
- id: google:gemini-3.1-flash-image-preview
|
||||
config:
|
||||
imageAspectRatio: '16:9'
|
||||
imageSize: '1K'
|
||||
tools:
|
||||
- googleSearch: {}
|
||||
|
||||
defaultTest:
|
||||
assert:
|
||||
- type: javascript
|
||||
value: output.length > 0 && (output.startsWith('data:image/') || output.startsWith('promptfoo://blob/'))
|
||||
|
||||
tests:
|
||||
- vars:
|
||||
city: 'Tokyo'
|
||||
- vars:
|
||||
city: 'Paris'
|
||||
@@ -0,0 +1,67 @@
|
||||
# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
|
||||
description: Gemini native image generation
|
||||
|
||||
prompts:
|
||||
- 'Create a {{quality}} image of {{subject}} with {{style}} aesthetic'
|
||||
|
||||
providers:
|
||||
# Gemini 2.5 Flash - Fast image generation (generally available)
|
||||
# Note: imageSize is not supported for Gemini 2.5 models
|
||||
- id: google:gemini-2.5-flash-image
|
||||
config:
|
||||
imageAspectRatio: '16:9'
|
||||
|
||||
# Gemini 3.1 Flash Image (Nano Banana 2)
|
||||
# imageSize supports: 512px, 1K, 2K, 4K (this model only; see per-model notes below)
|
||||
- id: google:gemini-3.1-flash-image
|
||||
config:
|
||||
imageAspectRatio: '16:9'
|
||||
imageSize: '2K'
|
||||
|
||||
# Gemini 3.1 Flash-Lite Image (Nano Banana 2 Lite)
|
||||
# Fastest, lowest-cost tier; 1K resolution only; no Google Search grounding
|
||||
- id: google:gemini-3.1-flash-lite-image
|
||||
config:
|
||||
imageAspectRatio: '16:9'
|
||||
imageSize: '1K'
|
||||
|
||||
# Gemini 3 Pro Image (Nano Banana Pro) — advanced generation, global endpoint only
|
||||
# imageSize supports: 1K, 2K, 4K
|
||||
- id: google:gemini-3-pro-image
|
||||
config:
|
||||
imageAspectRatio: '16:9'
|
||||
imageSize: '2K'
|
||||
|
||||
defaultTest:
|
||||
assert:
|
||||
# Verify that an image was generated (images land in the structured
|
||||
# providerResponse.images field; output alone is text when the model
|
||||
# also returns text parts)
|
||||
- type: javascript
|
||||
value: '(context.providerResponse?.images?.length ?? 0) > 0'
|
||||
|
||||
tests:
|
||||
- vars:
|
||||
quality: 'photorealistic'
|
||||
subject: 'a futuristic spacecraft'
|
||||
style: 'cinematic sci-fi'
|
||||
|
||||
- vars:
|
||||
quality: 'highly detailed'
|
||||
subject: 'starry night over a cyberpunk city'
|
||||
style: 'Van Gogh painting'
|
||||
|
||||
- vars:
|
||||
quality: 'minimalist'
|
||||
subject: 'a zen garden at sunrise'
|
||||
style: 'Japanese ink wash'
|
||||
|
||||
- vars:
|
||||
quality: 'vibrant'
|
||||
subject: 'tropical birds in a rainforest'
|
||||
style: 'watercolor illustration'
|
||||
|
||||
- vars:
|
||||
quality: 'dramatic'
|
||||
subject: 'a medieval castle during a thunderstorm'
|
||||
style: 'fantasy art'
|
||||
@@ -0,0 +1,65 @@
|
||||
# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
|
||||
description: Google Imagen image generation comparison
|
||||
|
||||
prompts:
|
||||
- 'Create a {{quality}} image of {{subject}} with {{style}} aesthetic'
|
||||
|
||||
providers:
|
||||
# Ultra quality - highest detail and quality
|
||||
- id: google:image:imagen-4.0-ultra-generate-001
|
||||
config:
|
||||
# projectId: 'your-project-id' # Optional: Can be set here or via GOOGLE_PROJECT_ID env var
|
||||
aspectRatio: '16:9'
|
||||
# seed: 42 # Note: seed is only supported in Vertex AI, not Google AI Studio
|
||||
# safetyFilterLevel: 'block_some' # Note: Google AI Studio only supports 'block_low_and_above'
|
||||
# addWatermark: false # Note: addWatermark is only supported in Vertex AI
|
||||
|
||||
# Standard quality - balanced quality and speed
|
||||
- id: google:image:imagen-4.0-generate-001
|
||||
config:
|
||||
aspectRatio: '16:9'
|
||||
# seed: 42 # Note: seed is only supported in Vertex AI
|
||||
# safetyFilterLevel: 'block_some' # Note: Google AI Studio only supports 'block_low_and_above'
|
||||
# addWatermark: false # Note: addWatermark is only supported in Vertex AI
|
||||
|
||||
# Fast generation - optimized for speed
|
||||
- id: google:image:imagen-4.0-fast-generate-001
|
||||
config:
|
||||
aspectRatio: '16:9'
|
||||
# seed: 42 # Note: seed is only supported in Vertex AI
|
||||
# safetyFilterLevel: 'block_some' # Note: Google AI Studio only supports 'block_low_and_above'
|
||||
# addWatermark: false # Note: addWatermark is only supported in Vertex AI
|
||||
|
||||
# Previous generation for comparison
|
||||
- id: google:image:imagen-3.0-generate-002
|
||||
config:
|
||||
aspectRatio: '16:9'
|
||||
# seed: 42 # Note: seed is only supported in Vertex AI
|
||||
# safetyFilterLevel: 'block_some' # Note: Google AI Studio only supports 'block_low_and_above'
|
||||
# addWatermark: false # Note: addWatermark is only supported in Vertex AI
|
||||
|
||||
tests:
|
||||
- vars:
|
||||
quality: 'photorealistic'
|
||||
subject: 'a futuristic spacecraft'
|
||||
style: 'cinematic sci-fi'
|
||||
|
||||
- vars:
|
||||
quality: 'highly detailed'
|
||||
subject: 'starry night over a cyberpunk city'
|
||||
style: 'Van Gogh painting'
|
||||
|
||||
- vars:
|
||||
quality: 'minimalist'
|
||||
subject: 'a zen garden at sunrise'
|
||||
style: 'Japanese ink wash'
|
||||
|
||||
- vars:
|
||||
quality: 'vibrant'
|
||||
subject: 'tropical birds in a rainforest'
|
||||
style: 'watercolor illustration'
|
||||
|
||||
- vars:
|
||||
quality: 'dramatic'
|
||||
subject: 'a medieval castle during a thunderstorm'
|
||||
style: 'fantasy art'
|
||||
Reference in New Issue
Block a user