Skip to content

feat(examples): add Image to Video AI custom provider example - #10993

Open
Anurag-M1 wants to merge 7 commits into
promptfoo:mainfrom
Anurag-M1:feat/provider-image-to-video-ai
Open

Anurag-M1 wants to merge 7 commits into
promptfoo:mainfrom
Anurag-M1:feat/provider-image-to-video-ai

Conversation

@Anurag-M1

Copy link
Copy Markdown

Summary

Adds an end-to-end custom provider example in examples/provider-image-to-video-ai demonstrating how to evaluate asynchronous image-to-video generation workflows with Promptfoo, addressing feature request #10168.

Motivation & Behavior

Image-to-video AI services (such as Image to Video AI, Runway, Kling, or Luma) follow an asynchronous pattern where jobs are submitted, polled until completion, and evaluated for output quality and media metadata.

This example provides:

  • A reusable custom provider in provider.js that manages task submission, polling with configurable backoff and timeout, and structured result formatting.
  • Deterministic demo simulation when IMAGE_TO_VIDEO_AI_API_KEY is unset or in test environments, ensuring local evaluations and CI run reliably without requiring paid API credentials.
  • Engaging test cases in promptfooconfig.yaml evaluating landscape camera motion, portrait subtle animation, and fluid macro dynamics.
  • Assertions checking output video URL format, task completion status, duration matching, and latency SLA thresholds.
  • Unit tests in test/examples/imageToVideoProvider.test.ts verifying provider initialization, simulation fallback, live polling flows, timeout handling, and error branches.

Closes #10168

Verification

  • Unit tests: npm test -- test/examples/imageToVideoProvider.test.ts (10/10 passed)
  • YAML compatibility: npm test -- test/examples/yaml-aliases.test.ts (passed)
  • TestSuite schema validation: npm test -- test/types/index.test.ts (390/390 passed, including new config)
  • Local eval run: npm run local -- eval -c examples/provider-image-to-video-ai/promptfooconfig.yaml --no-cache (3/3 test cases passed in 0s)
  • Code quality: npm run tsc, npm run l, npm run f, and npx knip passed cleanly with 0 errors.

@codecov

codecov Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.73%. Comparing base (aaeebf2) to head (6c09ee1).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10993      +/-   ##
==========================================
- Coverage   89.73%   89.73%   -0.01%     
==========================================
  Files        1051     1051              
  Lines       92781    92781              
  Branches    32855    32855              
==========================================
- Hits        83261    83260       -1     
- Misses       9520     9521       +1     
Flag Coverage Δ
backend 90.44% <ø> (-0.01%) ⬇️
site 53.49% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mldangelo mldangelo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot merge this as a working service integration yet. The default API hostname does not resolve in the current DNS check, and I could not find a published API contract for the /generate and /tasks endpoints on the linked service site. Please provide the documented endpoint/authentication/response contract, or make this an explicitly generic local simulation without claiming that these URLs represent generated media. I also reproduced the cancellation and reported-metadata defects below using the exact PR head and controlled responses. No credentials or paid generation requests were used.


try {
// 1. Submit video generation job
const submitRes = await fetch(`${this.baseUrl}/generate`, {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Bound requests and propagate cancellation. maxPollAttempts only bounds the number of completed fetches; submission and each poll can wait indefinitely. A pre-aborted third-argument abortSignal still starts fetch, and the call remains pending when that fetch hangs. Accept the provider call options, combine caller cancellation with an overall deadline, and pass the resulting signal to both requests and polling waits.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in 1c411f1. callApi now accepts options.abortSignal, immediately checks for pre-aborted signals without initiating requests, and combines caller cancellation with an overall deadline (timeoutMs, default 60s) via AbortSignal.any, propagating the signal to both submission/polling fetches and polling sleep intervals. Added unit tests covering pre-aborted cancellation, in-flight polling cancellation, and deadline timeouts.

jobId,
status,
videoUrl: resultVideoUrl,
duration,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Report observed media properties instead of echoing the request. With a completed response reporting duration 1, fps 10 and resolution 320x240, a request for 5s/30fps/1920x1080 is returned as 5s/30fps/1920x1080. The example duration assertions therefore pass even when the generated media differs. Normalize actual response metadata from the documented API (or inspect the returned media) and keep requested settings in separately named fields.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in 1c411f1. Observed media properties from the completed task response payload (duration, fps, resolution, motion) are now normalized and reported in output and metadata, while requested parameters are preserved in separately named fields (requestedDuration, requestedFps, requestedResolution, requestedMotion, requested). Added unit tests asserting that mismatched observed properties are reported accurately.

@Anurag-M1

Copy link
Copy Markdown
Author

Thanks for the thorough review @mldangelo. I have updated the PR to address all points:

  1. Explicit Generic Local Simulation: The example and documentation have been re-framed as an explicitly generic local simulation and reference implementation for async video generation workflows. The default base URL now points to https://api.example.com/v1, and simulated runs return synthetic placeholder URLs rather than claiming to represent live generated media.
  2. Cancellation & Overall Deadline: callApi now accepts options.abortSignal, checks for pre-aborted signals before initiating requests, and combines caller cancellation with an overall deadline (timeoutMs, default 60s) via AbortSignal.any across all submission, polling fetches, and backoff sleeps.
  3. Observed vs Requested Media Metadata: Actual media attributes returned in the task status payload are normalized into metadata.duration, metadata.fps, and metadata.resolution (and reflected in output), while requested parameters are preserved in separately named fields (requestedDuration, requestedFps, requestedResolution, requestedMotion, requested).
  4. Tests: Added coverage for pre-aborted signals, cancellation during poll sleep, overall timeout, and observed property discrepancies (15/15 unit tests passing, clean tsc, lint, and format).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Add Image to Video AI custom provider example

3 participants