Skip to content

Commit

Permalink
fix: Leading whitespace chunks break partial parser
Browse files Browse the repository at this point in the history
  • Loading branch information
tillkolter committed Dec 5, 2024
1 parent ddb27b6 commit 7327a60
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lib/ChatCompletionStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,9 @@ export class ChatCompletionStream<ParsedT = null>
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;
}
}

Expand Down

0 comments on commit 7327a60

Please sign in to comment.