feat(image): add --seed for reproducible generations#44
Open
mvanhorn wants to merge 1 commit into
Open
Conversation
|
@mvanhorn is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
| ? parseAspectRatio(opts.aspectRatio) | ||
| : undefined; | ||
| const provOpts = buildProviderOptions(opts); | ||
| const seed = opts.seed ? parsePositiveInt(opts.seed, "seed") : undefined; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
--seed <n>toai image. The flag is forwarded togenerateImageas the SDK's top-levelseedoption, so providers that honor it (BFL, Stability, fal, and other supported models) return reproducible images for a given (prompt, model, seed) tuple.Why this matters
The repo's tagline is "predictable artifact outputs" but
ai imagehas no way to ask for a specific seed today. Seeded generation is the canonical reproducibility primitive across most image CLIs (replicate, fal, the Stable Diffusion UIs). With this flag, prompt iteration becomes a clean diff on the prompt rather than two changing variables.Demo
Simulated demo. Real image generation needs an AI Gateway key, so the demo uses placeholder gradients to make the contrast visible:
Without
--seed, two runs of the same prompt produce different outputs. With--seed 42, two runs produce identical outputs.Changes
packages/ai-cli/src/commands/image.ts: add--seed <n>option, parse viaparsePositiveInt, forward as the SDK's top-levelseedargument. Print a warning on stderr when every selected model is OpenAI (gpt-image ignores seed). Print a separate warning when--seedis combined with-n > 1, since the generations would be identical on supported providers.packages/ai-cli/src/commands/completions.ts: add--seedtoIMAGE_FLAGSand the zsh image flag list so tab completion picks it up in bash, zsh, and fish.packages/ai-cli/README.md: add the--seed <n>row to the image flag block and a short note describing the SDK pass-through, the OpenAI exception, and the-n > 1caveat.Testing
The new test asserts
ai image --seed abc xexits 1 with--seed must be a positive integer. The two warning paths follow the existing--quality/--stylewarning shape, so no new coverage was added for them.buildProviderOptionsstays the only place provider-specific keys are assembled; the OpenAI quality/style branch is unchanged.