diff --git a/src/Agent/AgentRunner.php b/src/Agent/AgentRunner.php index be95105..e9bd71c 100644 --- a/src/Agent/AgentRunner.php +++ b/src/Agent/AgentRunner.php @@ -128,7 +128,19 @@ final readonly class AgentRunner yield $this->systemMsg("Ich rufe Shopdaten ab (type: " . $commerceIntent . ")", "think"); //Search in swag by ai optimized query - $shopResults = $swagFullOutPut ? $this->shopSearchService->search($swagFullOutPut, $commerceIntent) : ''; + try { + $shopResults = $swagFullOutPut !== '' + ? $this->shopSearchService->search($swagFullOutPut, $commerceIntent) + : []; + } catch (Throwable $e) { + $this->agentLogger->warning('Shop search failed, continuing without shop results', [ + 'userId' => $userId, + 'exception' => $e, + ]); + + $shopResults = []; + yield $this->systemMsg('Shopdaten konnten nicht geladen werden, ich antworte mit Wissensbasis weiter...', 'think'); + } } if ($commerceIntent === CommerceIntentLite::PRODUCT_SEARCH) { @@ -203,8 +215,8 @@ final readonly class AgentRunner $finalChunk = $chunker->flush(); if ($finalChunk !== null) { yield $this->systemMsg($finalChunk, 'answer'); - } else { - yield $this->systemMsg('... no more data received from llm', 'err'); + } elseif ($fullOutput === '') { + yield $this->systemMsg('❌ Es wurden keine Daten vom LLM empfangen.', 'err'); } // --------------------------------------------------------- @@ -229,7 +241,7 @@ final readonly class AgentRunner 'exception' => $e, ]); - $this->systemMsg("\n❌ An internal error occurred while processing the request. \nError: " . $e->getMessage(), 'err'); + yield $this->systemMsg("\n❌ An internal error occurred while processing the request. \nError: " . $e->getMessage(), 'err'); } } diff --git a/src/Commerce/CommerceQueryParser.php b/src/Commerce/CommerceQueryParser.php index ed7adaf..e91f3f5 100644 --- a/src/Commerce/CommerceQueryParser.php +++ b/src/Commerce/CommerceQueryParser.php @@ -73,7 +73,7 @@ final class CommerceQueryParser */ private function extractPriceRange(string $prompt): array { - $priceMin = 10; + $priceMin = 0; $priceMax = null; if (preg_match('/\bzwischen\s+(\d+(?:[.,]\d+)?)\s+und\s+(\d+(?:[.,]\d+)?)\s+euro\b/u', $prompt, $m) === 1) { diff --git a/src/Controller/AskSseController.php b/src/Controller/AskSseController.php index 4a70a74..245079b 100644 --- a/src/Controller/AskSseController.php +++ b/src/Controller/AskSseController.php @@ -58,12 +58,16 @@ final readonly class AskSseController // --------------------------------------------------------- // 🔥 FIXED: Sende Chunks direkt (behält \n!) // --------------------------------------------------------- - foreach ($this->agentRunner->run($prompt, $clientId,true) as $chunk) { - // Normalize line endings - $chunk = str_replace(["\r\n", "\r"], "\n", $chunk); + try { + foreach ($this->agentRunner->run($prompt, $clientId, true) as $chunk) { + $chunk = str_replace(["\r\n", "\r"], "\n", $chunk); + $this->sendData($chunk); + } - // Sende Chunk direkt mit \n - $this->sendData($chunk); + $this->sendEvent('done', '[DONE]'); + } catch (\Throwable $e) { + $this->sendData('❌ Stream abgebrochen: ' . $e->getMessage() . ''); + $this->sendEvent('done', '[DONE]'); } // --------------------------------------------------------- diff --git a/src/Intent/CommerceIntentLite.php b/src/Intent/CommerceIntentLite.php index fd19010..605e65f 100644 --- a/src/Intent/CommerceIntentLite.php +++ b/src/Intent/CommerceIntentLite.php @@ -38,6 +38,7 @@ final class CommerceIntentLite 'alternativ', 'find', 'shop', + 'store', 'sku', 'Artikel', 'Gerät', @@ -46,7 +47,8 @@ final class CommerceIntentLite 'Titromat', 'Seminar', 'Schulung', - 'Sensor' + 'Sensor', + 'liste' ]; foreach ($strongSignals as $signal) {