diff --git a/src/StreamHandler.php b/src/StreamHandler.php index b8c70d2..ef95a27 100644 --- a/src/StreamHandler.php +++ b/src/StreamHandler.php @@ -32,7 +32,7 @@ public function handle() $rawResult = $lastLine; - $newChunks = collect($lines)->map(fn ($line) => $this->convertLineToArray($line))->filter()->map(fn ($line) => new StreamedChatChunk($line)); + $newChunks = collect($lines)->map(fn ($line) => $this->convertLineToArray($line))->filter(fn ($value) => $value !== null)->map(fn ($line) => new StreamedChatChunk($line)); $allChunks = $allChunks->merge($newChunks); if ($firstLoop) { @@ -40,8 +40,8 @@ public function handle() } ($this->streamCallback)( - $newChunks->map(fn ($streamChunk) => $streamChunk->choices[0]['delta']['content'] ?? null)->filter()->join(''), - $allChunks->map(fn ($streamChunk) => $streamChunk->choices[0]['delta']['content'] ?? null)->filter()->join(''), + $newChunks->map(fn ($streamChunk) => $streamChunk->choices[0]['delta']['content'] ?? null)->filter(fn ($value) => $value !== null)->join(''), + $allChunks->map(fn ($streamChunk) => $streamChunk->choices[0]['delta']['content'] ?? null)->filter(fn ($value) => $value !== null)->join(''), ); $firstLoop = false;