Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/fresh-colts-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"workers-ai-provider": patch
---

Enhance response handling for number types.
This PR addresses a critical bug in the implementation that caused non-output when streaming responses from models like Llama4 that can return numeric chunks.
The issue stemmed from an inadequate check on incoming stream chunks, which assumed all chunks would have a .length property, leading to errors with non-string data types.
13 changes: 13 additions & 0 deletions packages/workers-ai-provider/src/streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ export function getMappedStream(response: Response) {
});
}

// Handling number responses for models like Llama4
if (typeof chunk.response === "number") {
if (!textId) {
textId = generateId();
controller.enqueue({ type: "text-start", id: textId });
}
controller.enqueue({
type: "text-delta",
id: textId,
delta: String(chunk.response),
});
}

// Handle reasoning content
const reasoningDelta = chunk?.choices?.[0]?.delta?.reasoning_content;
if (reasoningDelta?.length) {
Expand Down