harden runner errors
This commit is contained in:
@@ -26,7 +26,9 @@ final readonly class AgentRunner
|
||||
private bool $debug,
|
||||
private bool $logPrompt,
|
||||
private bool $logContext,
|
||||
) {}
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
public function run(string $prompt, string $userId): Generator
|
||||
{
|
||||
@@ -88,7 +90,12 @@ final readonly class AgentRunner
|
||||
$chunker = new StreamChunker();
|
||||
|
||||
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 === '') {
|
||||
continue;
|
||||
@@ -108,6 +115,8 @@ final readonly class AgentRunner
|
||||
$finalChunk = $chunker->flush();
|
||||
if ($finalChunk !== null) {
|
||||
yield $finalChunk;
|
||||
} else {
|
||||
yield '... no data received from llm';
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------
|
||||
@@ -130,7 +139,7 @@ final readonly class AgentRunner
|
||||
'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