Repository navigation
fix: sync Anthropic usage chunks and Gemini input_audio from Python any-llm - #33
Merged
Merged
Conversation
…ny-llm Port mozilla-ai/any-llm through 3727a2b: trailing Anthropic usage-only stream chunks, Gemini input_audio format mapping, and HTTP status from attached SDK responses. Co-authored-by: Anurag Roy <anuragroy@duck.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
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.
Sync with mozilla-ai/any-llm
mainthrough3727a2b(5 new commits since9b3448f). One PR for the applicable library changes. No unmerged cursor[bot] sync PR was open, so this is a new PR.Ported
message_stopchunk withchoices: [], matching OpenAI's usage-only chunk.message_deltastill carriesfinishReason. Consumers that read usage withif (chunk.choices.length === 0)now work for Anthropic the same way they do for OpenAI and MiniMax. Azure Anthropic and Vertex Anthropic inherit the converter. If the SDK attaches an accumulatedmessage.usageon stop, that wins over the tokens collected frommessage_start/message_delta.input_audioparts; this aligns the remaining request shape. Format names map toaudio/<format>(wav, mp3, flac, ogg, …), missingdata/formatraiseInvalidRequestError, invalid base64 is rejected, and the 20 MB inline limit is checked from the encoded length before decoding. Data-URL payloads remain accepted. Vertex AI inherits the same conversion.normalizeProviderErrornow reads HTTP status from an attachedresponse.statusCode/response.statuswhen the error object itself has none. Same idea as Python reading aiohttp'sresponse.statusafterstatus_code.Already present (tests added)
content: null.Skipped (not applicable)
Tracked source SHA is now
3727a2bf3c36dec36677a42d7bd7a4b3141af48a.oxfmtandoxlintwere run after the changes.Note
Medium Risk
Anthropic streaming consumers that assumed usage on the finish-reason chunk must read the trailing empty-choices chunk; Gemini audio validation is stricter and may reject previously tolerated payloads.
Overview
Syncs any-llm-ts with Python any-llm at
3727a2b(parity manifest, porting docs, patch release notes; package version 0.5.0).Anthropic streaming now matches OpenAI-style usage chunks:
message_deltastill carriesfinishReason(and refusal/stop details) but no longer attachesusagethere. Final token counts (including cache fields when present) land on a trailingmessage_stopchunk withchoices: [], preferring accumulatedmessage.usageon stop when the SDK provides it. Azure/Vertex Anthropic adapters inherit this path.Gemini
input_audioaccepts any stringformat(not just mp3/wav), maps{ data, format }toaudio/<format>inline MIME types, requires both fields viaInvalidRequestError, and centralizes base64 + 20 MB inline validation (including size check from encoded length before decode). Docs reflect flac/ogg and similar formats.Error normalization also reads HTTP status from nested
response.statusCode/response.statuson SDK error objects (aiohttp-style), so 4xx mapping works when status is not on the top-level error.Tests cover the new stream usage contract, Gemini audio conversion/validation, attached-response status parsing, and Bedrock non-streaming assistant text alongside tool calls (regression coverage only; no Bedrock adapter logic change in this PR).
Reviewed by Cursor Bugbot for commit 1ffa165. Bugbot is set up for automated code reviews on this repo. Configure here.