add used sources

This commit is contained in:
team 1
2026-04-17 08:26:21 +02:00
parent 84ba528036
commit 4247825528
2 changed files with 24 additions and 2 deletions

View File

@@ -44,6 +44,7 @@ final readonly class AgentRunner
$swagFullOutPut = '';
$firstThinkLoop = true;
$shopResults = [];
$sources = [];
if ($prompt === '') {
yield '❌ Empty prompt.';
@@ -70,13 +71,18 @@ final readonly class AgentRunner
// ---------------------------------------------------------
yield $this->systemMsg("Ich prüfe auf Internet Quellen...", "think");
$urlContent = $this->urlAnalyzer->extractContentFromPrompt($prompt);
if($urlContent){
$sources[]= 'Externe URL';
}
// ---------------------------------------------------------
// 3) Retrieve RAG knowledge
// ---------------------------------------------------------
yield $this->systemMsg("Ich hole relevante Daten aus meinem RAG Wissen...", "think");
$knowledgeChunks = $this->retriever->retrieve($prompt);
if($knowledgeChunks){
$sources[]= 'RAG Wissen';
}
// ---------------------------------------------------------
// 4) commerce/shop search
// ---------------------------------------------------------
@@ -126,6 +132,10 @@ final readonly class AgentRunner
}
}
if($shopResults){
$sources[]= 'Shopsystem';
}
if ($commerceIntent === CommerceIntentLite::PRODUCT_SEARCH) {
$knowledgeChunks = array_slice($knowledgeChunks, 0, 2);
} elseif ($commerceIntent === CommerceIntentLite::ADVISORY_PRODUCT_SEARCH) {
@@ -168,6 +178,10 @@ final readonly class AgentRunner
$chunker->flush();
$this->thinkSuppressor->reset();
if($sources){
yield $this->systemMsg("Genutze Quellen: ".implode(', ',$sources), 'info');
}
foreach ($this->ollamaClient->stream($finalPrompt) as $token) {
if (!is_string($token)) {
@@ -202,6 +216,10 @@ final readonly class AgentRunner
yield $this->systemMsg('❌ Es wurden keine Daten vom LLM empfangen.', 'err');
}
if($sources){
yield $this->systemMsg("Quellen: ".implode(', ',$sources), 'info');
}
// ---------------------------------------------------------
// 7) Persist conversation history
// ---------------------------------------------------------
@@ -237,7 +255,8 @@ final readonly class AgentRunner
return match ($type) {
'answer' => '' . $msg,
'err' => '<span class="text-danger">' . $msg . "</span>\n<hr>\n",
'think' => '<span class="text-info think">' . $msg . "</span>\n"
'think' => '<span class="text-info think">' . $msg . "</span>\n",
'info' => "\n\n<span class=\"text-info fw-bolder\">" . $msg . "</span>\n"
};
}
}

View File

@@ -81,6 +81,7 @@ final readonly class PromptBuilder
if($swagFullOutPut){
$shopBlock = "SHOP SEARCH QUERY: " . trim($swagFullOutPut)."\n";
$shopBlock .= "Source: Shop Search\n";
}
if ($shopResults !== []) {
@@ -158,12 +159,14 @@ final readonly class PromptBuilder
$knowledgeParts[] =
"RETRIEVED KNOWLEDGE (supporting):\n" .
"Source: Documents \n".
implode("\n\n", $lines);
}
if ($urlContent !== '') {
$knowledgeParts[] =
"CONTENT FROM URL (supporting):\n" .
"Source: URL \n".
$urlContent;
}