add used sources
This commit is contained in:
@@ -44,6 +44,7 @@ final readonly class AgentRunner
|
|||||||
$swagFullOutPut = '';
|
$swagFullOutPut = '';
|
||||||
$firstThinkLoop = true;
|
$firstThinkLoop = true;
|
||||||
$shopResults = [];
|
$shopResults = [];
|
||||||
|
$sources = [];
|
||||||
|
|
||||||
if ($prompt === '') {
|
if ($prompt === '') {
|
||||||
yield '❌ Empty prompt.';
|
yield '❌ Empty prompt.';
|
||||||
@@ -70,13 +71,18 @@ final readonly class AgentRunner
|
|||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
yield $this->systemMsg("Ich prüfe auf Internet Quellen...", "think");
|
yield $this->systemMsg("Ich prüfe auf Internet Quellen...", "think");
|
||||||
$urlContent = $this->urlAnalyzer->extractContentFromPrompt($prompt);
|
$urlContent = $this->urlAnalyzer->extractContentFromPrompt($prompt);
|
||||||
|
if($urlContent){
|
||||||
|
$sources[]= 'Externe URL';
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// 3) Retrieve RAG knowledge
|
// 3) Retrieve RAG knowledge
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
yield $this->systemMsg("Ich hole relevante Daten aus meinem RAG Wissen...", "think");
|
yield $this->systemMsg("Ich hole relevante Daten aus meinem RAG Wissen...", "think");
|
||||||
$knowledgeChunks = $this->retriever->retrieve($prompt);
|
$knowledgeChunks = $this->retriever->retrieve($prompt);
|
||||||
|
if($knowledgeChunks){
|
||||||
|
$sources[]= 'RAG Wissen';
|
||||||
|
}
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// 4) commerce/shop search
|
// 4) commerce/shop search
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
@@ -126,6 +132,10 @@ final readonly class AgentRunner
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($shopResults){
|
||||||
|
$sources[]= 'Shopsystem';
|
||||||
|
}
|
||||||
|
|
||||||
if ($commerceIntent === CommerceIntentLite::PRODUCT_SEARCH) {
|
if ($commerceIntent === CommerceIntentLite::PRODUCT_SEARCH) {
|
||||||
$knowledgeChunks = array_slice($knowledgeChunks, 0, 2);
|
$knowledgeChunks = array_slice($knowledgeChunks, 0, 2);
|
||||||
} elseif ($commerceIntent === CommerceIntentLite::ADVISORY_PRODUCT_SEARCH) {
|
} elseif ($commerceIntent === CommerceIntentLite::ADVISORY_PRODUCT_SEARCH) {
|
||||||
@@ -168,6 +178,10 @@ final readonly class AgentRunner
|
|||||||
$chunker->flush();
|
$chunker->flush();
|
||||||
$this->thinkSuppressor->reset();
|
$this->thinkSuppressor->reset();
|
||||||
|
|
||||||
|
if($sources){
|
||||||
|
yield $this->systemMsg("Genutze Quellen: ".implode(', ',$sources), 'info');
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($this->ollamaClient->stream($finalPrompt) as $token) {
|
foreach ($this->ollamaClient->stream($finalPrompt) as $token) {
|
||||||
|
|
||||||
if (!is_string($token)) {
|
if (!is_string($token)) {
|
||||||
@@ -202,6 +216,10 @@ final readonly class AgentRunner
|
|||||||
yield $this->systemMsg('❌ Es wurden keine Daten vom LLM empfangen.', 'err');
|
yield $this->systemMsg('❌ Es wurden keine Daten vom LLM empfangen.', 'err');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($sources){
|
||||||
|
yield $this->systemMsg("Quellen: ".implode(', ',$sources), 'info');
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
// 7) Persist conversation history
|
// 7) Persist conversation history
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
@@ -237,7 +255,8 @@ final readonly class AgentRunner
|
|||||||
return match ($type) {
|
return match ($type) {
|
||||||
'answer' => '' . $msg,
|
'answer' => '' . $msg,
|
||||||
'err' => '<span class="text-danger">' . $msg . "</span>\n<hr>\n",
|
'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"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,6 +81,7 @@ final readonly class PromptBuilder
|
|||||||
|
|
||||||
if($swagFullOutPut){
|
if($swagFullOutPut){
|
||||||
$shopBlock = "SHOP SEARCH QUERY: " . trim($swagFullOutPut)."\n";
|
$shopBlock = "SHOP SEARCH QUERY: " . trim($swagFullOutPut)."\n";
|
||||||
|
$shopBlock .= "Source: Shop Search\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($shopResults !== []) {
|
if ($shopResults !== []) {
|
||||||
@@ -158,12 +159,14 @@ final readonly class PromptBuilder
|
|||||||
|
|
||||||
$knowledgeParts[] =
|
$knowledgeParts[] =
|
||||||
"RETRIEVED KNOWLEDGE (supporting):\n" .
|
"RETRIEVED KNOWLEDGE (supporting):\n" .
|
||||||
|
"Source: Documents \n".
|
||||||
implode("\n\n", $lines);
|
implode("\n\n", $lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($urlContent !== '') {
|
if ($urlContent !== '') {
|
||||||
$knowledgeParts[] =
|
$knowledgeParts[] =
|
||||||
"CONTENT FROM URL (supporting):\n" .
|
"CONTENT FROM URL (supporting):\n" .
|
||||||
|
"Source: URL \n".
|
||||||
$urlContent;
|
$urlContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user