optimize flow retrieval
This commit is contained in:
@@ -93,7 +93,7 @@ final readonly class AgentRunner
|
|||||||
|
|
||||||
yield $this->systemMsg("Ich optimere die Recherche...", "think");
|
yield $this->systemMsg("Ich optimere die Recherche...", "think");
|
||||||
|
|
||||||
//Call ai for optimized swag query
|
//Call AI for optimized swag query
|
||||||
foreach ($this->ollamaClient->stream($promptSwagSearch) as $swagToken) {
|
foreach ($this->ollamaClient->stream($promptSwagSearch) as $swagToken) {
|
||||||
|
|
||||||
if (!is_string($swagToken)) {
|
if (!is_string($swagToken)) {
|
||||||
@@ -111,7 +111,7 @@ final readonly class AgentRunner
|
|||||||
|
|
||||||
yield $this->systemMsg("Ich rufe Recherchedaten ab (type: " . $commerceIntent . ")", "think");
|
yield $this->systemMsg("Ich rufe Recherchedaten ab (type: " . $commerceIntent . ")", "think");
|
||||||
|
|
||||||
//Search in swag by ai optimized query
|
//Search in swag by AI optimized query
|
||||||
try {
|
try {
|
||||||
$shopResults = $swagFullOutPut !== ''
|
$shopResults = $swagFullOutPut !== ''
|
||||||
? $this->shopSearchService->search($swagFullOutPut, $commerceIntent)
|
? $this->shopSearchService->search($swagFullOutPut, $commerceIntent)
|
||||||
@@ -122,7 +122,6 @@ final readonly class AgentRunner
|
|||||||
'exception' => $e,
|
'exception' => $e,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$shopResults = [];
|
|
||||||
yield $this->systemMsg('Shopdaten konnten nicht geladen werden, ich antworte mit Wissensbasis weiter...', 'think');
|
yield $this->systemMsg('Shopdaten konnten nicht geladen werden, ich antworte mit Wissensbasis weiter...', 'think');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ final readonly class PromptBuilder
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($product->customFields) {
|
if ($product->customFields) {
|
||||||
$parts[] = "Meta-Informationen: " . $product->customFields;
|
$parts[] = "Meta-Information: " . $product->customFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
$lines[] = implode("\n", $parts);
|
$lines[] = implode("\n", $parts);
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ final readonly class ShopSearchService
|
|||||||
private bool $enabled = true,
|
private bool $enabled = true,
|
||||||
private int $maxResults = 25,
|
private int $maxResults = 25,
|
||||||
private string $baseUrl
|
private string $baseUrl
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,12 +66,12 @@ final readonly class ShopSearchService
|
|||||||
}
|
}
|
||||||
|
|
||||||
$results[] = new ShopProductResult(
|
$results[] = new ShopProductResult(
|
||||||
id: (string) ($row['id'] ?? ''),
|
id: (string)($row['id'] ?? ''),
|
||||||
name: trim((string) ($row['translated']['name'] ?? '')),
|
name: trim((string)($row['translated']['name'] ?? '')),
|
||||||
productNumber: isset($row['productNumber']) ? (string) $row['productNumber'] : null,
|
productNumber: isset($row['productNumber']) ? (string)$row['productNumber'] : null,
|
||||||
manufacturer: $this->extractManufacturer($row),
|
manufacturer: $this->extractManufacturer($row),
|
||||||
price: $this->extractPrice($row),
|
price: $this->extractPrice($row),
|
||||||
available: isset($row['available']) ? (bool) $row['available'] : null,
|
available: isset($row['available']) ? (bool)$row['available'] : null,
|
||||||
url: $this->baseUrl . $this->extractUrl($row),
|
url: $this->baseUrl . $this->extractUrl($row),
|
||||||
highlights: $this->extractHighlights($row),
|
highlights: $this->extractHighlights($row),
|
||||||
description: $this->cleanUpDescription($row),
|
description: $this->cleanUpDescription($row),
|
||||||
@@ -81,7 +82,7 @@ final readonly class ShopSearchService
|
|||||||
|
|
||||||
return array_values(array_filter(
|
return array_values(array_filter(
|
||||||
$results,
|
$results,
|
||||||
static fn (ShopProductResult $product): bool => $product->name !== ''
|
static fn(ShopProductResult $product): bool => $product->name !== ''
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,12 +98,13 @@ final readonly class ShopSearchService
|
|||||||
private function cleanUpDescription(array $description): string
|
private function cleanUpDescription(array $description): string
|
||||||
{
|
{
|
||||||
if (isset($description['translated']['description'])) {
|
if (isset($description['translated']['description'])) {
|
||||||
$newDesc = strip_tags((string) $description['translated']['description']);
|
$newDesc = strip_tags((string)$description['translated']['description']);
|
||||||
|
$newDesc = html_entity_decode($newDesc);
|
||||||
$newDesc = preg_replace('/^[ \t]*\R/m', '', $newDesc);
|
$newDesc = preg_replace('/^[ \t]*\R/m', '', $newDesc);
|
||||||
$newDesc = preg_replace('/[ \t]{2,}/', ' ', $newDesc);
|
$newDesc = preg_replace('/[ \t]{2,}/', ' ', $newDesc);
|
||||||
$result = trim((string) $newDesc);
|
$result = trim((string)$newDesc);
|
||||||
|
|
||||||
return mb_substr($result, 0, 500);
|
return mb_substr($result, 0, 1500);
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
@@ -140,7 +142,7 @@ final readonly class ShopSearchService
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return number_format((float) $unitPrice, 2, ',', '.') . ' €';
|
return number_format((float)$unitPrice, 2, ',', '.') . ' €';
|
||||||
}
|
}
|
||||||
|
|
||||||
private function extractUrl(array $row): ?string
|
private function extractUrl(array $row): ?string
|
||||||
@@ -173,7 +175,7 @@ final readonly class ShopSearchService
|
|||||||
$highlights = [];
|
$highlights = [];
|
||||||
|
|
||||||
if (isset($row['available'])) {
|
if (isset($row['available'])) {
|
||||||
$highlights[] = (bool) $row['available'] ? 'Verfügbar' : 'Nicht verfügbar';
|
$highlights[] = (bool)$row['available'] ? 'Verfügbar' : 'Nicht verfügbar';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($row['productNumber']) && is_string($row['productNumber']) && trim($row['productNumber']) !== '') {
|
if (isset($row['productNumber']) && is_string($row['productNumber']) && trim($row['productNumber']) !== '') {
|
||||||
|
|||||||
Reference in New Issue
Block a user