feat: add text block support for Bedrock Anthropic messages#86
feat: add text block support for Bedrock Anthropic messages#86Pratham-Mishra04 wants to merge 1 commit intographite-base/86from
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Summary by CodeRabbit
Summary by CodeRabbit
WalkthroughA conditional check was added in the Changes
Poem
✨ Finishing Touches
🧪 Generate Unit Tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
✅ BugBot reviewed your changes and found no bugs!
BugBot free trial expires on June 17, 2025
You have used $0.00 of your $50.00 spend limit so far. Manage your spend limit in the Cursor dashboard.
Was this report helpful? Give feedback by reacting with 👍 or 👎
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
core/providers/bedrock.go(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#55
File: core/providers/anthropic.go:526-550
Timestamp: 2025-06-04T09:29:46.287Z
Learning: In core/providers/anthropic.go, the content field in formattedMessages is always of type []interface{} because it's explicitly constructed that way upstream in the prepareAnthropicChatRequest function. Defensive type casting for multiple types is not needed since the type is guaranteed by the construction logic.
core/providers/bedrock.go (1)
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#55
File: core/providers/anthropic.go:526-550
Timestamp: 2025-06-04T09:29:46.287Z
Learning: In core/providers/anthropic.go, the content field in formattedMessages is always of type []interface{} because it's explicitly constructed that way upstream in the prepareAnthropicChatRequest function. Defensive type casting for multiple types is not needed since the type is guaranteed by the construction logic.
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Graphite / mergeability_check
- GitHub Check: Graphite / mergeability_check
d06a1d9 to
efd98ff
Compare
2791720 to
cb71ba7
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
core/providers/bedrock.go(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#55
File: core/providers/anthropic.go:526-550
Timestamp: 2025-06-04T09:29:46.287Z
Learning: In core/providers/anthropic.go, the content field in formattedMessages is always of type []interface{} because it's explicitly constructed that way upstream in the prepareAnthropicChatRequest function. Defensive type casting for multiple types is not needed since the type is guaranteed by the construction logic.
core/providers/bedrock.go (1)
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#55
File: core/providers/anthropic.go:526-550
Timestamp: 2025-06-04T09:29:46.287Z
Learning: In core/providers/anthropic.go, the content field in formattedMessages is always of type []interface{} because it's explicitly constructed that way upstream in the prepareAnthropicChatRequest function. Defensive type casting for multiple types is not needed since the type is guaranteed by the construction logic.
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Graphite / mergeability_check
- GitHub Check: Graphite / mergeability_check
| if block.Text != nil { | ||
| content = append(content, BedrockAnthropicTextMessage{ | ||
| Type: "text", | ||
| Text: *block.Text, | ||
| }) | ||
| } |
There was a problem hiding this comment.
🧹 Nitpick (assertive)
Guard against empty or whitespace-only text blocks
While the new nil check prevents pointer dereferences, empty strings still generate no-op messages. Filter out blocks with empty or whitespace-only text to keep the payload clean.
Apply this diff:
@@ -521,7 +521,8 @@
- if block.Text != nil {
+ if block.Text != nil && strings.TrimSpace(*block.Text) != "" {
content = append(content, BedrockAnthropicTextMessage{
Type: "text",
Text: *block.Text,
})📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if block.Text != nil { | |
| content = append(content, BedrockAnthropicTextMessage{ | |
| Type: "text", | |
| Text: *block.Text, | |
| }) | |
| } | |
| if block.Text != nil && strings.TrimSpace(*block.Text) != "" { | |
| content = append(content, BedrockAnthropicTextMessage{ | |
| Type: "text", | |
| Text: *block.Text, | |
| }) | |
| } |
🤖 Prompt for AI Agents
In core/providers/bedrock.go around lines 522 to 527, the code appends text
messages even if the text is empty or contains only whitespace. To fix this, add
a check to ensure block.Text is not nil and that the dereferenced string is not
empty or whitespace-only before appending the message. Use a string trimming
function to verify the text content is meaningful and skip appending if it is
empty after trimming.

Added support for text content blocks in Bedrock Anthropic chat completions. This change allows the provider to properly handle text blocks within content blocks, ensuring they are included in the message content sent to the Bedrock API.