20 lines
511 B
PHP
20 lines
511 B
PHP
<?php
|
|
|
|
namespace App\Domains\Ai\Actions;
|
|
|
|
use App\Domains\Ai\Services\AiService;
|
|
|
|
class GenerateSlug
|
|
{
|
|
public function __construct(private AiService $ai) {}
|
|
|
|
public function handle(string $targetUrl): string
|
|
{
|
|
$prompt = "Generate a short, memorable URL slug (3-8 chars, lowercase, hyphens only) for this URL: {$targetUrl}. Reply with ONLY the slug, no explanation.";
|
|
|
|
$slug = $this->ai->complete($prompt);
|
|
|
|
return preg_replace('/[^a-z0-9-]/', '', strtolower($slug));
|
|
}
|
|
}
|