2026-05-17 22:43:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Infrastructure\AI\Agent;
|
|
|
|
|
|
|
|
|
|
use App\Infrastructure\AI\OllamaClientInterface;
|
2026-05-18 07:19:02 +00:00
|
|
|
use App\Infrastructure\AI\PromptTemplateService;
|
2026-05-18 08:35:52 +00:00
|
|
|
use App\Infrastructure\Search\WebSearchInterface;
|
2026-05-17 22:43:47 +00:00
|
|
|
|
|
|
|
|
final class SpecsResearchAgent
|
|
|
|
|
{
|
|
|
|
|
public function __construct(
|
2026-05-18 07:19:02 +00:00
|
|
|
private readonly OllamaClientInterface $client,
|
|
|
|
|
private readonly PromptTemplateService $prompts,
|
2026-05-18 08:35:52 +00:00
|
|
|
private readonly WebSearchInterface $search,
|
2026-05-17 22:43:47 +00:00
|
|
|
private readonly string $model,
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-18 07:19:02 +00:00
|
|
|
public function research(string $modelName, string $articleTypeName, string $manufacturer = ''): string
|
2026-05-17 22:43:47 +00:00
|
|
|
{
|
2026-05-18 07:19:02 +00:00
|
|
|
$subject = trim(($manufacturer !== '' ? $manufacturer.' ' : '').$modelName);
|
2026-05-17 22:43:47 +00:00
|
|
|
|
2026-05-18 08:35:52 +00:00
|
|
|
$searchResults = $this->search->search("{$subject} {$articleTypeName} specifications");
|
|
|
|
|
|
2026-05-18 07:19:02 +00:00
|
|
|
$prompt = $this->prompts->render('specs_research', [
|
|
|
|
|
'articleType' => $articleTypeName,
|
|
|
|
|
'subject' => $subject,
|
2026-05-18 08:35:52 +00:00
|
|
|
'searchResults' => $searchResults !== '' ? $searchResults : 'No web results available.',
|
2026-05-18 07:19:02 +00:00
|
|
|
]);
|
2026-05-17 22:43:47 +00:00
|
|
|
|
2026-05-18 08:35:52 +00:00
|
|
|
$result = $this->client->generate($this->model, $prompt);
|
2026-05-17 22:43:47 +00:00
|
|
|
|
2026-05-18 07:19:02 +00:00
|
|
|
if ('' === trim($result)) {
|
|
|
|
|
throw new \RuntimeException("No specifications found for model: {$modelName}");
|
|
|
|
|
}
|
2026-05-17 22:43:47 +00:00
|
|
|
|
2026-05-18 07:19:02 +00:00
|
|
|
return $result;
|
2026-05-17 22:43:47 +00:00
|
|
|
}
|
|
|
|
|
}
|