fix: handle non-text first content block in AnthropicProvider#753
Open
TemRevil wants to merge 1 commit into
Open
fix: handle non-text first content block in AnthropicProvider#753TemRevil wants to merge 1 commit into
TemRevil wants to merge 1 commit into
Conversation
The Messages API response is not guaranteed to start with a text block: Anthropic-compatible endpoints (and Anthropic with extended thinking enabled) can emit a thinking/reasoning block before the text block. Indexing response.content[0].text then raised 'ThinkingBlock object has no attribute text' and crashed every generation. Scan response.content for the first block that carries text instead of assuming block 0 is text. Falls back to an empty string if no text block is present. Fixes repowise-dev#750
|
✅ Health: 7.7 (unchanged) 📋 At a glance Files & modules (2)
🩹 Review priority (files here with the most recent bug-fix history — defects cluster, so review these first)
🔎 More signals (2)🔥 Hotspots touched (2)
🔗 Hidden coupling (2 files)
📊 Full report · ⭐ Star Repowise · 📥 Install bot · Last updated 2026-07-10 12:58 UTC |
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.
Fixes #750
AnthropicProviderassumedresponse.content[0]is always aTextBlockand read.textfrom it. Some Anthropic-compatible endpoints (and Anthropic itself with extended thinking) put a thinking/reasoning block first, so that access raised'ThinkingBlock' object has no attribute 'text'and crashed every generation, as reported in #740 against Kimi's endpoint.Following the approach in the issue, added a
_first_text_block()helper that scansresponse.contentfor the first block carrying text instead of indexing block 0 (falling back to an empty string).Added
test_generate_skips_leading_non_text_block, which mocks a response whose content is[thinking_block, text_block](the thinking blockspec'd without.textso accessing it raisesAttributeError, matching the real crash) and asserts the text block's content is returned.