Repository navigation
Conversation
🦋 Changeset detectedLatest commit: d2c054b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Llama models on Workers AI stream a hybrid event: the same piece is in the native fields and in the OpenAI-style delta of the same event.
getMappedStreamreads both, so text comes out twice and tool-call arguments are concatenated twice:Streams that use only one of the two shapes take the same path as before.
createAIis not affected.createAIfromagents/models/ai-sdk(0.33.0), the adapter the README now recommends for the binding, reads text and tool calls only fromchoices[0].delta, so it reads each piece once. Checked against the live binding: withllama-3.3-70b-instruct-fp8-fastandllama-4-scout-17b-16e-instruct,createAI+streamTextreturned "The capital of Australia is Canberra." once and a validadd_to_listcall ({"items": ["milk"]}). This PR fixes the paths that still go throughgetMappedStream: credentials mode (accountId+apiKey, not deprecated), the AI Search chat model, and existingcreateWorkersAI({ binding })users.Evidence
Before:
streamTextthrough the binding with@cf/meta/llama-4-scout-17b-16e-instruct:"TheThe capital capital of of Australia Australia is is Canberra Canberra..";AI_InvalidToolInputError: each argument piece appears twice, so the JSON doesn't parse.A Worker counting the events of a short streamed answer through the binding found text in both fields in every text event, with or without
tools:responseanddelta.contentTool-call events carried the same piece in
tool_callsandchoices[0].delta.tool_calls, every time.After: three new tests in
test/stream-text.test.ts(Binding - Streaming Text Tests). The first two fail onmainand pass here:pnpm exec vitest --watch=falseinpackages/workers-ai-provider: 22 files, 457 tests pass (454 before, plus the 3 new).tsc --noEmitis clean.Merge Danger
Door: two-way
Blast Radius: streaming
Only
getMappedStreamchanges. Binding mode, credentials mode (REST/ai/run) and the AI Search chat model all read their streams through it. The one behaviour change, for an event that carries text in both fields:responsenow wins overdelta.content. On Workers AI those were identical in every event observed.