From 7327a6082db58a00ecd169a43f3fc3e0ea21e1a1 Mon Sep 17 00:00:00 2001 From: Till Kolter Date: Thu, 5 Dec 2024 16:36:45 +0100 Subject: [PATCH] fix: Leading whitespace chunks break partial parser --- src/lib/ChatCompletionStream.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/ChatCompletionStream.ts b/src/lib/ChatCompletionStream.ts index a88f8a23b..80bac5607 100644 --- a/src/lib/ChatCompletionStream.ts +++ b/src/lib/ChatCompletionStream.ts @@ -509,7 +509,9 @@ export class ChatCompletionStream choice.message.content = (choice.message.content || '') + content; if (!choice.message.refusal && this.#getAutoParseableResponseFormat()) { - choice.message.parsed = partialParse(choice.message.content); + // Even a partial parser does not accept empty string + const trimmed = choice.message.content.trimStart(); + choice.message.parsed = trimmed ? partialParse(trimmed) : null; } }