From 00fb2201a69acf8f6aaad3f1d7a96ee871823dbb Mon Sep 17 00:00:00 2001 From: Celestial Rose Date: Sat, 8 Nov 2025 23:06:35 +0200 Subject: [PATCH 1/2] Enhance response handling for number types Updated response handling to support number types. --- packages/workers-ai-provider/src/streaming.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/workers-ai-provider/src/streaming.ts b/packages/workers-ai-provider/src/streaming.ts index c3a9952e..d4b569f5 100644 --- a/packages/workers-ai-provider/src/streaming.ts +++ b/packages/workers-ai-provider/src/streaming.ts @@ -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) { From 4e7ca23f6aa4107d372739e197272d0043e9b18a Mon Sep 17 00:00:00 2001 From: Celestial Rose Date: Sat, 8 Nov 2025 23:58:42 +0200 Subject: [PATCH 2/2] adds the changeset --- .changeset/fresh-colts-study.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changeset/fresh-colts-study.md diff --git a/.changeset/fresh-colts-study.md b/.changeset/fresh-colts-study.md new file mode 100644 index 00000000..74c9f43d --- /dev/null +++ b/.changeset/fresh-colts-study.md @@ -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.