optimize url detection

This commit is contained in:
team 1
2026-04-14 18:56:20 +02:00
parent fe6eb25d25
commit b452607e2c
4 changed files with 498 additions and 65 deletions

View File

@@ -40,6 +40,8 @@ final readonly class AgentRunner
{
$prompt = trim($prompt);
$swagFullOutPut = '';
$firstThinkLoop = true;
$shopResults = [];
if ($prompt === '') {
yield '❌ Empty prompt.';
@@ -61,7 +63,28 @@ final readonly class AgentRunner
yield $this->systemMsg("Ich analysiere deine Anfrage...", "think");
$promptSwagSearch = '
// ---------------------------------------------------------
// 2) Extract URL content (if present)
// ---------------------------------------------------------
yield $this->systemMsg("Ich prüfe auf Internet Quellen...", "think");
$urlContent = $this->urlAnalyzer->extractContentFromPrompt($prompt);
// ---------------------------------------------------------
// 3) Retrieve RAG knowledge
// ---------------------------------------------------------
yield $this->systemMsg("Ich hole relevante Daten aus meinem RAG Wissen...", "think");
$knowledgeChunks = $this->retriever->retrieve($prompt);
// ---------------------------------------------------------
// 4) commerce/shop search
// ---------------------------------------------------------
$commerceMeta = $this->commerceIntentLite->detect($prompt);
$commerceIntent = (string)($commerceMeta['intent'] ?? CommerceIntentLite::NONE);
if ($commerceIntent === CommerceIntentLite::PRODUCT_SEARCH || $commerceIntent === CommerceIntentLite::ADVISORY_PRODUCT_SEARCH) {
//PreOptimize swag search query
$promptSwagSearch = '
Erzeuge aus dem folgenden Nutzereingabetext einen kurzen Suchtext für die Shopware-6-Suche.
Regeln:
@@ -78,63 +101,43 @@ final readonly class AgentRunner
Ausgabeformat:
Keyword1 Keyword2 Keyword3
Text: ' . $prompt . '
Nutzereingabetext: ' . $prompt . '
';
$this->thinkSuppressor->reset();
//Reset thinkSuppressor
$this->thinkSuppressor->reset();
foreach ($this->ollamaClient->stream($promptSwagSearch) as $swagToken) {
yield $this->systemMsg("Ich optimere die Shopanfrage...", "think");
if (!is_string($swagToken)) {
continue;
//Call ai for optimized swag query
foreach ($this->ollamaClient->stream($promptSwagSearch) as $swagToken) {
if (!is_string($swagToken)) {
continue;
}
$swagCleanToken = $this->thinkSuppressor->filter($swagToken);
if ($swagCleanToken === '') {
continue;
}
$swagFullOutPut .= $swagCleanToken;
}
$swagCleanToken = $this->thinkSuppressor->filter($swagToken);
yield $this->systemMsg("Ich rufe Shopdaten ab (type: " . $commerceIntent . ")", "think");
if ($swagCleanToken === '') {
continue;
}
$swagFullOutPut .= $swagCleanToken;
//Search in swag by ai optimized query
$shopResults = $swagFullOutPut ? $this->shopSearchService->search($swagFullOutPut, $commerceIntent) : '';
}
yield $this->systemMsg("Ich habe folgende Keywords an die Shopsuche geschickt: " . $swagFullOutPut, "think");
// ---------------------------------------------------------
// 2) Extract URL content (if present)
// ---------------------------------------------------------
$urlContent = $this->urlAnalyzer->extractContentFromPrompt($prompt);
// ---------------------------------------------------------
// 3) Retrieve RAG knowledge
// ---------------------------------------------------------
yield $this->systemMsg("Ich hole relevante Daten aus meinem RAG Wissen...", "think");
$knowledgeChunks = $this->retriever->retrieve($prompt);
// ---------------------------------------------------------
// 4) commerce/shop search
// ---------------------------------------------------------
$commerceMeta = $this->commerceIntentLite->detect($prompt);
$commerceIntent = (string)($commerceMeta['intent'] ?? CommerceIntentLite::NONE);
yield $this->systemMsg("Ich rufe Shopdaten ab (type: " . $commerceIntent . ")", "think");
$shopResults = $swagFullOutPut ? $this->shopSearchService->search($swagFullOutPut, $commerceIntent) : '';
if ($commerceIntent === CommerceIntentLite::PRODUCT_SEARCH) {
$knowledgeChunks = array_slice($knowledgeChunks, 0, 2);
} elseif ($commerceIntent === CommerceIntentLite::ADVISORY_PRODUCT_SEARCH) {
$knowledgeChunks = array_slice($knowledgeChunks, 0, 3);
}
if ($shopResults) {
yield $this->systemMsg("Ich verarbeite Shopdaten...", "think");
} else {
yield $this->systemMsg("Ich habe keine releveanten Shopdaten gefunden...", "think");
}
yield $this->systemMsg("Ich analysiere gefundene Informationen...", "think");
yield $this->systemMsg("Ich analysiere alle Informationen...", "think");
// ---------------------------------------------------------
// 5) Build final prompt
@@ -179,8 +182,10 @@ final readonly class AgentRunner
$cleanToken = $this->thinkSuppressor->filter((string)$token);
if ($cleanToken === '') {
yield $this->systemMsg("Denke nach...", "think");
usleep(500);
if ($firstThinkLoop) {
yield $this->systemMsg("Denke nach...", "think");
$firstThinkLoop = false;
}
continue;
}