Skip to content

Conversation

yutao-dev
Copy link

Pull Request: Add Spring AI Video Generation Extension Module

Overview

This PR introduces a complete video generation extension module for the Spring AI framework, providing video generation capabilities while adhering to Spring AI's core design philosophy and architectural standards. The module delivers an end-to-end solution covering video generation, task status management, and result storage.

Key Features

1. Core Video Generation

  • Implements the Spring AI-compliant VideoModel interface and its implementation class VideoModelImpl.
  • Provides a VideoClient with fluent chaining and builder pattern support for parameter construction.
  • Supports both text-to-video and image-to-video modalities, compatible with multiple video generation models.

2. Task Status Management

  • Implements an in-memory storage mechanism InMemoryVideoStorage for task tracking.
  • Supports full task lifecycle states: IN_QUEUEIN_PROGRESSSUCCEED/FAILED.
  • Extensible storage interface VideoStorage for custom persistence implementations.

3. Automated Polling Mechanism

  • Includes VideoTimer, a scheduled task scanner that automatically polls for incomplete video generation tasks.
  • Supports timeout handling and task cleanup mechanisms.
  • Configurable polling intervals, timeout durations, and other parameters via property files.

4. Flexible Configuration

  • Supports video generation parameters: prompt, model, imageSize, negativePrompt, referenceImage, and seed.
  • Detailed configuration options customizable via application.yaml.

Architecture

Module Structure

spring-ai-model/src/main/java/org/springframework/ai/video

video/
├── api/# Video API client
├── client/# Video client implementation
├── model/# Video model classes
├── option/# Configuration options
├── storage/# Task storage management
└── trimer/# Scheduled task handling

Workflow

  1. User submits a video generation request via VideoClient.
  2. Request is routed through VideoModel to call the video service API.
  3. The video service returns a request ID, with the task status initialized to IN_QUEUE.
  4. VideoStorage persists task metadata.
  5. VideoTimer periodically polls for task status updates.
  6. Upon completion, the task status is updated to SUCCEED or FAILED.

Usage Example

// Build video options
VideoOptions options = VideoOptionsImpl.builder()
.prompt("A corgi running on the beach")
.model("Wan-AI/Wan2.2-T2V-A14B")
.negativePrompt("blurry, low quality")
.build();

// Initialize components
VideoApi videoApi = VideoApi.builder()
.apiKey("your-api-key")
.baseUrl("https://api.video-service.com")
.videoPath("v1/video/submit")
.build();

VideoModel videoModel = new VideoModelImpl(videoApi);
VideoStorage videoStorage = new InMemoryVideoStorage();
VideoClient videoClient = new VideoClient(videoModel, videoStorage);

// Generate video
String requestId = videoClient.param()
.prompt("A corgi running on the beach")
.model("Wan-AI/Wan2.2-T2V-A14B")
.negativePrompt("blurry, low quality")
.getOutput();

System.out.println("Video request ID: " + requestId);

Configuration Options

Property Description Default Value
ai.video.timer.enabled Enable scheduled polling true
ai.video.timer.timeout Task timeout (ms) 300000 (5 minutes)
ai.video.timer.ttl Task storage TTL (ms) 86400000 (24h)
ai.video.timer.interval Polling interval (ms) 30000 (30 seconds)

Compatibility

This module aligns with Spring AI design principles and integrates seamlessly with existing Spring AI components:

  • Implements the standard Model interface.
  • Follows Spring AI configuration and dependency injection patterns.
  • Works with Spring Boot's scheduled tasks and REST client infrastructure.

Future Enhancements

  1. Extend storage mechanisms to support Redis and other persistent solutions.
  2. Add multi-vendor API adapters for broader video service compatibility.
  3. Introduce advanced video processing features (editing, format conversion).

This module has been fully tested and is ready for integration into the Spring AI ecosystem, providing developers with robust video generation capabilities.

Signed-off-by: NotJustCatCoder <1357329777@qq.com>
@ilayaperumalg
Copy link
Member

@yutao-dev Thanks for the proposal introducing video client!

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants