diff --git a/migrations/Version20260520070000.php b/migrations/Version20260520070000.php new file mode 100644 index 0000000..454dbd1 --- /dev/null +++ b/migrations/Version20260520070000.php @@ -0,0 +1,65 @@ +addSql('UPDATE app.prompt_templates SET body = :body, updated_at = NOW() WHERE key = :key', [ + 'body' => $title, 'key' => 'ebay_title', + ]); + $this->addSql('UPDATE app.prompt_templates SET body = :body, updated_at = NOW() WHERE key = :key', [ + 'body' => $description, 'key' => 'ebay_description', + ]); + } + + public function down(Schema $schema): void + { + $this->addSql("UPDATE app.prompt_templates SET body = 'Create a concise eBay listing title (max 80 characters) for this {{typeName}}.\nDevice: {{deviceLabel}}\nUse the most important specifications. Include condition if not \"new\".\nCondition: {{condition}}\n{{specsSection}}\nReturn ONLY the title text, no quotes, no explanation.', updated_at = NOW() WHERE key = 'ebay_title'"); + $this->addSql("UPDATE app.prompt_templates SET body = 'Create a professional eBay listing description in German for this {{typeName}}.\nDevice: {{deviceLabel}}\nInclude all available specifications in a clear, structured format.\nMention the condition: {{condition}}.\n{{conditionNotes}}\n{{specsSection}}\nUse HTML formatting (ul, li, strong tags). Max 2000 characters.', updated_at = NOW() WHERE key = 'ebay_description'"); + } +} diff --git a/src/Infrastructure/AI/Agent/EbayTextAgent.php b/src/Infrastructure/AI/Agent/EbayTextAgent.php index d7c30b2..bf4f2b8 100644 --- a/src/Infrastructure/AI/Agent/EbayTextAgent.php +++ b/src/Infrastructure/AI/Agent/EbayTextAgent.php @@ -17,6 +17,15 @@ final class EbayTextAgent ) { } + private function extractBetweenDelimiters(string $raw): string + { + if (preg_match('/---\s*\n(.*?)\n\s*---/s', $raw, $matches)) { + return trim($matches[1]); + } + + return trim($raw); + } + /** @return array{title: string, description: string} */ public function generate(Article $article, string $specsText = ''): array { @@ -32,8 +41,9 @@ final class EbayTextAgent $condition = $article->getCondition()->value; $conditionNotes = $article->getConditionNotes() ?? ''; $manufacturer = $article->getManufacturer() ?? ''; + $modelName = $article->getModelName() ?? ''; $modelNumber = $article->getModelNumber() ?? ''; - $deviceLabel = trim("{$manufacturer} {$modelNumber}") ?: $typeName; + $deviceLabel = trim("{$manufacturer} {$modelName} {$modelNumber}") ?: $typeName; $specsSection = $attributeText !== '' ? "Known attributes:\n{$attributeText}" @@ -54,8 +64,8 @@ final class EbayTextAgent 'specsSection' => $specsSection, ]); - $title = trim($this->ollama->generate($this->model, $titlePrompt)); - $description = trim($this->ollama->generate($this->model, $descriptionPrompt)); + $title = $this->extractBetweenDelimiters($this->ollama->generate($this->model, $titlePrompt)); + $description = $this->extractBetweenDelimiters($this->ollama->generate($this->model, $descriptionPrompt)); if (mb_strlen($title) > 80) { $title = mb_substr($title, 0, 77).'...';