StoryboardHandler (#37): breaks the project's script into a numbered scene-by-scene breakdown (description + image prompt per scene) via OpenAI in JSON mode (added json_mode support to OpenAiDriver for reliable structured output), stored as a JSON asset. VideoGenerationHandler (#38): generates one still image per storyboard scene via StabilityAI — the scene *visuals*, not motion/video clips (no text-to-video model integrated; see the task comment for why). VideoEditingHandler (#39): the step that actually produces a video file — assembles the scene stills into an MP4 via ffmpeg's concat demuxer, timed to the voiceover audio's duration (probed via ffprobe) or a fixed per-scene duration if there's no audio, then muxes the audio track in. Verified against the real ffmpeg/ffprobe binaries on this box, not just Process::fake(). Asset previews (#45, #46): a reusable partial renders each asset inline by type — image/audio/video get real playback elements, text/ JSON gets a truncated <pre> block, everything else a download link. Wired into both the awaiting_approval step view (so approving/ rejecting is an actual content review, not just a word count) and a general project assets grid. Also fixes a latent bug in AssetStorage::url(), found while wiring up previews: it called Storage::url() on the default 'local' disk, which has no configured URL driver and throws in production — only worked before because Storage::fake() is more permissive than the real local driver. Now serves assets through a new authenticated streaming route instead (VideoProjectAssetController). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
53 lines
1.8 KiB
PHP
53 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Support\AiProviders;
|
|
|
|
use App\Models\AiProvider;
|
|
use Illuminate\Http\Client\ConnectionException;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
/**
|
|
* Text generation via OpenAI's Chat Completions API. Used for scripts,
|
|
* metadata (titles/descriptions/tags), and similar text content.
|
|
*/
|
|
class OpenAiDriver implements AiProviderDriver
|
|
{
|
|
public function generate(AiProvider $provider, string $prompt, array $options = []): AiGenerationResult
|
|
{
|
|
$model = $options['model'] ?? $provider->config['model'] ?? 'gpt-4o-mini';
|
|
|
|
$body = [
|
|
'model' => $model,
|
|
'messages' => [
|
|
['role' => 'user', 'content' => $prompt],
|
|
],
|
|
];
|
|
|
|
// Ask the API to guarantee valid JSON back, for callers that need
|
|
// structured output (e.g. a storyboard's scene breakdown). The
|
|
// prompt itself must still ask for JSON — this only enforces it.
|
|
if ($options['json_mode'] ?? false) {
|
|
$body['response_format'] = ['type' => 'json_object'];
|
|
}
|
|
|
|
try {
|
|
$response = Http::withToken($provider->api_key)
|
|
->post('https://api.openai.com/v1/chat/completions', $body);
|
|
} catch (ConnectionException $e) {
|
|
throw new AiGenerationException("could not connect to OpenAI: {$e->getMessage()}");
|
|
}
|
|
|
|
if ($response->failed()) {
|
|
throw new AiGenerationException($response->json('error.message') ?? 'unexpected response from OpenAI');
|
|
}
|
|
|
|
$content = $response->json('choices.0.message.content');
|
|
|
|
if (! $content) {
|
|
throw new AiGenerationException('unexpected response from OpenAI: missing message content');
|
|
}
|
|
|
|
return new AiGenerationResult($content, 'text/plain', $response->json());
|
|
}
|
|
}
|