Adding Video Support to the Laravel AI SDK
One of the Shopify Apps I've been working on recently uses PrismPHP. PrismPHP forms some of the foundation of the Laravel AI SDK which we hope to switch to at some point however for most of the development of our app, the Laravel AI SDK required a PHP84 minimum, we're currently on PHP83.
One of the features our app has is the ability to generate images via AI, either completely from scratch OR by feeding in up to 3 source images. This is really cool but one of the ideas I had for a future version of the app, is to allow AI generated videos to be created too.
I'm not 100% sure on the reason, but neither PrismPHP or the Laravel AI SDK have anything in place for video generation, so I set to work adding it to the latter!
I really love the syntax of being able to generate an image with the SDK:
$image = Image::of('A donut sitting on the kitchen counter')->generate();So I wanted to keep it similar. I eventually landed on this:
Video::of('A short clip of a city at night with neon lights')
->queue(provider: 'openai')
->onQueue('process-videos')
->then(fn ($response) => $response->storePublicly(path: 'videos', disk: 'public'))
->catch(fn (\Throwable $e) => report($e));The onQueue is particularly important. You probably do not want this to run in sync because of how long it takes, so dispatching to a queue and having it processed via a job makes sense.
I created a simple demo application to test it out, so taking the prompt above, this is what happens:
Example of generating AI videos
The original video was a bit longer, I trimmed out most of the wait time so you can see the good stuff quicker!
The PR is yet to be merged, but you can take a look at the implementation below. Pushpak, from the Laravel team has actually assigned themself to the PR, so could this mean it's going to get worked on further and we'll soon see it in the package? Hopefully!