Implementation:Ollama Ollama Imagegen CLI
| Knowledge Sources | |
|---|---|
| Domains | Image Generation, CLI |
| Last Updated | 2025-02-15 00:00 GMT |
Overview
Provides CLI commands and interactive mode for image generation models in Ollama.
Description
The cli.go file implements command-line interface support for image generation, including flag registration for width, height, steps, seed, and negative prompt. It provides both one-shot and interactive generation modes, handling image path extraction from prompts and progress display via spinners and step bars. The interactive mode supports dynamic option changes via slash commands (e.g., /set width 512).
Usage
Used when users run image generation models through the Ollama CLI, either in one-shot mode with a prompt or in interactive chat mode.
Code Reference
Source Location
- Repository: Ollama
- File: x/imagegen/cli.go
- Lines: 1-576
Signature
type ImageGenOptions struct {
Width int
Height int
Steps int
Seed int
NegativePrompt string
}
func DefaultOptions() ImageGenOptions
func RegisterFlags(cmd *cobra.Command)
func AppendFlagsDocs(cmd *cobra.Command)
func RunCLI(cmd *cobra.Command, name string, prompt string, interactive bool, keepAlive *api.Duration) error
Import
import "github.com/ollama/ollama/x/imagegen"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| cmd | *cobra.Command | Yes | Cobra command with registered flags |
| name | string | Yes | Model name for generation |
| prompt | string | Yes | Text prompt for image generation |
| interactive | bool | Yes | Whether to enter interactive mode |
| keepAlive | *api.Duration | No | Keep-alive duration for model |
Outputs
| Name | Type | Description |
|---|---|---|
| error | error | Any error from generation or CLI operations |
Usage Examples
opts := imagegen.DefaultOptions()
opts.Width = 512
opts.Height = 512
err := imagegen.RunCLI(cmd, "flux2-klein", "a sunset over mountains", false, nil)