harden runner errors
This commit is contained in:
@@ -26,7 +26,9 @@ final readonly class AgentRunner
|
|||||||
private bool $debug,
|
private bool $debug,
|
||||||
private bool $logPrompt,
|
private bool $logPrompt,
|
||||||
private bool $logContext,
|
private bool $logContext,
|
||||||
) {}
|
)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public function run(string $prompt, string $userId): Generator
|
public function run(string $prompt, string $userId): Generator
|
||||||
{
|
{
|
||||||
@@ -88,7 +90,12 @@ final readonly class AgentRunner
|
|||||||
$chunker = new StreamChunker();
|
$chunker = new StreamChunker();
|
||||||
|
|
||||||
foreach ($this->ollamaClient->stream($finalPrompt) as $token) {
|
foreach ($this->ollamaClient->stream($finalPrompt) as $token) {
|
||||||
$cleanToken = $this->thinkSuppressor->filter($token);
|
|
||||||
|
if (!is_string($token)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$cleanToken = $this->thinkSuppressor->filter((string)$token);
|
||||||
|
|
||||||
if ($cleanToken === '') {
|
if ($cleanToken === '') {
|
||||||
continue;
|
continue;
|
||||||
@@ -108,6 +115,8 @@ final readonly class AgentRunner
|
|||||||
$finalChunk = $chunker->flush();
|
$finalChunk = $chunker->flush();
|
||||||
if ($finalChunk !== null) {
|
if ($finalChunk !== null) {
|
||||||
yield $finalChunk;
|
yield $finalChunk;
|
||||||
|
} else {
|
||||||
|
yield '... no data received from llm';
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
@@ -130,7 +139,7 @@ final readonly class AgentRunner
|
|||||||
'exception' => $e,
|
'exception' => $e,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
yield "\n❌ An internal error occurred while processing the request.";
|
yield "\n❌ An internal error occurred while processing the request. \nError: " . $e->getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user