@effect/ai-anthropic: responses whose usage has only input_tokens and output_tokens fail to decode (Anthropic-compatible gateways)
メンテナーはふだん 1 日以内に返信
評価
この issue はまだ評価されていません。
説明
What version of Effect is running?
effect and @effect/ai-anthropic from main at 16fe80030.
What steps can reproduce the bug?
Point AnthropicClient.layer({ apiKey, apiUrl }) at an Anthropic-compatible gateway that sends a minimal usage object, and call LanguageModel.generateText or LanguageModel.streamText. I used freellmapi's /v1/messages, which answers with:
// non-streaming message, and message_start in a stream
"usage": { "input_tokens": 3, "output_tokens": 1 }
// message_delta
"usage": { "output_tokens": 1 }
What is the expected behavior?
The response decodes. These fields only feed cache accounting, which already falls back when they are missing or null (cache_creation_input_tokens ?? 0).
What do you see instead?
generateText: AnthropicClient.createMessage: Invalid response: Missing key
at ["usage"]["cache_creation"]
streamText: AnthropicClient.createMessageStream: Invalid response: Missing key
at [0]["data"]["message"]["usage"]["cache_creation"]
Adding the missing keys one by one, the generated schemas require:
BetaMessage.usageandBetaMessageStartEvent.message.usage:cache_creation,cache_creation_input_tokens,cache_read_input_tokens,service_tierBetaMessageDeltaEvent.usage:cache_creation_input_tokens,cache_read_input_tokens,input_tokens
Additional information
Same kind of problem as #8464 (inference_geo), which was fixed with codegen.yml replacements. If these keys become optional, the message_delta handler needs a change too: it checks Predicate.isNotNull(event.usage.input_tokens) (AnthropicLanguageModel.ts:2209, and the two cache fields below it), and undefined passes that check, so a delta without input_tokens would set the input count to undefined. Predicate.isNotNullish avoids that. Happy to open a PR with both if that helps.
- 主要言語
- TypeScript
- スター
- 16.7k
- フォーク
- 808
- 平均マージ
- 11時間 33分
- マージ済み PR(30日)
- 855
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Effect-TS/effect のほかの issue
-
`fromJsonSchemaDocument`: import open `patternProperties`対応中かも @effect-bot が今日担当しました。 オープン
Effect-TS/effect#10048 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
`fromJsonSchemaDocument`: intersect an object with `anyOf` branches that re-declare an enum propertyオープン
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
メンテナーはふだん 1 日以内に返信
-
`fromJsonSchemaDocument`: import `dependentRequired` (draft-07 `dependencies`)対応中かも @effect-bot が今日担当しました。 オープン
Effect-TS/effect#10046 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
`fromJsonSchemaDocument`: import `if` / `then` / `else`対応中かも @effect-bot が今日担当しました。 オープン
Effect-TS/effect#10045 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
`fromJsonSchemaDocument`: import the `not` keyword対応中かも @effect-bot が今日担当しました。 オープン
Effect-TS/effect#10044 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
Effect-TS/effect の issue をすべて見る
似ている issue
-
[Bug]: Pen taps on sidebar rows start a drag and lose their click対応中かも @makhnatkin が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
b310-digital/teammapper#1515 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
puckeditor/puck#1884 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
outline/outline#14378 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
nicobailon/pi-web-access#642 ·
メンテナーはふだん 1 日以内に返信