|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace App\Ai\Agents; |
| 6 | + |
| 7 | +use App\Models\Workspace; |
| 8 | +use Illuminate\Contracts\JsonSchema\JsonSchema; |
| 9 | +use Laravel\Ai\Attributes\Temperature; |
| 10 | +use Laravel\Ai\Contracts\Agent; |
| 11 | +use Laravel\Ai\Contracts\HasStructuredOutput; |
| 12 | +use Laravel\Ai\Enums\Lab; |
| 13 | +use Laravel\Ai\Promptable; |
| 14 | + |
| 15 | +#[Temperature(0.25)] |
| 16 | +class PostImageRegenerator implements Agent, HasStructuredOutput |
| 17 | +{ |
| 18 | + use Promptable; |
| 19 | + |
| 20 | + public function __construct( |
| 21 | + public Workspace $workspace, |
| 22 | + ) {} |
| 23 | + |
| 24 | + public function instructions(): string |
| 25 | + { |
| 26 | + return view('prompts.post_image.regenerator', [ |
| 27 | + 'content_language' => $this->workspace->content_language ?: 'en', |
| 28 | + ])->render(); |
| 29 | + } |
| 30 | + |
| 31 | + public function schema(JsonSchema $schema): array |
| 32 | + { |
| 33 | + return [ |
| 34 | + 'title' => $schema->string() |
| 35 | + ->description('Updated short title for the image (max ~120 chars).') |
| 36 | + ->required(), |
| 37 | + 'body' => $schema->string() |
| 38 | + ->description('Updated supporting text for the image (max ~240 chars).') |
| 39 | + ->required(), |
| 40 | + 'keywords' => $schema->array() |
| 41 | + ->items($schema->string()) |
| 42 | + ->description('3-10 short keywords for image generation context.') |
| 43 | + ->required(), |
| 44 | + 'change_mode' => $schema->string() |
| 45 | + ->enum(['image_only', 'text_only', 'both']) |
| 46 | + ->description('Set to image_only (change visual only), text_only (change text only), or both (change visual and text).') |
| 47 | + ->required(), |
| 48 | + ]; |
| 49 | + } |
| 50 | + |
| 51 | + public function provider(): Lab |
| 52 | + { |
| 53 | + return match (config('ai.default')) { |
| 54 | + 'openai' => Lab::OpenAI, |
| 55 | + 'anthropic' => Lab::Anthropic, |
| 56 | + default => Lab::Gemini, |
| 57 | + }; |
| 58 | + } |
| 59 | + |
| 60 | + public function model(): string |
| 61 | + { |
| 62 | + return config('ai.default_text_model'); |
| 63 | + } |
| 64 | +} |
0 commit comments