SuperSeller3000/src/Infrastructure/AI/Agent/SpecsResearchAgent.php

37 lines
1,013 B
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace App\Infrastructure\AI\Agent;
use App\Infrastructure\AI\OllamaClientInterface;
use App\Infrastructure\AI\PromptTemplateService;
final class SpecsResearchAgent
{
public function __construct(
private readonly OllamaClientInterface $client,
private readonly PromptTemplateService $prompts,
private readonly string $model,
) {
}
public function research(string $modelName, string $articleTypeName, string $manufacturer = ''): string
{
$subject = trim(($manufacturer !== '' ? $manufacturer.' ' : '').$modelName);
$prompt = $this->prompts->render('specs_research', [
'articleType' => $articleTypeName,
'subject' => $subject,
]);
$result = $this->client->generateWithWebSearch($this->model, $prompt);
if ('' === trim($result)) {
throw new \RuntimeException("No specifications found for model: {$modelName}");
}
return $result;
}
}