mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-03 07:33:45 +00:00
fix: filter empty content blocks for Bedrock provider (#14586)
This commit is contained in:
@@ -51,7 +51,7 @@ export namespace ProviderTransform {
|
||||
): ModelMessage[] {
|
||||
// Anthropic rejects messages with empty content - filter out empty string messages
|
||||
// and remove empty text/reasoning parts from array content
|
||||
if (model.api.npm === "@ai-sdk/anthropic") {
|
||||
if (model.api.npm === "@ai-sdk/anthropic" || model.api.npm === "@ai-sdk/amazon-bedrock") {
|
||||
msgs = msgs
|
||||
.map((msg) => {
|
||||
if (typeof msg.content === "string") {
|
||||
|
||||
@@ -1096,6 +1096,38 @@ describe("ProviderTransform.message - anthropic empty content filtering", () =>
|
||||
expect(result[0].content[1]).toEqual({ type: "text", text: "Result" })
|
||||
})
|
||||
|
||||
test("filters empty content for bedrock provider", () => {
|
||||
const bedrockModel = {
|
||||
...anthropicModel,
|
||||
id: "amazon-bedrock/anthropic.claude-opus-4-6",
|
||||
providerID: "amazon-bedrock",
|
||||
api: {
|
||||
id: "anthropic.claude-opus-4-6",
|
||||
url: "https://bedrock-runtime.us-east-1.amazonaws.com",
|
||||
npm: "@ai-sdk/amazon-bedrock",
|
||||
},
|
||||
}
|
||||
|
||||
const msgs = [
|
||||
{ role: "user", content: "Hello" },
|
||||
{ role: "assistant", content: "" },
|
||||
{
|
||||
role: "assistant",
|
||||
content: [
|
||||
{ type: "text", text: "" },
|
||||
{ type: "text", text: "Answer" },
|
||||
],
|
||||
},
|
||||
] as any[]
|
||||
|
||||
const result = ProviderTransform.message(msgs, bedrockModel, {})
|
||||
|
||||
expect(result).toHaveLength(2)
|
||||
expect(result[0].content).toBe("Hello")
|
||||
expect(result[1].content).toHaveLength(1)
|
||||
expect(result[1].content[0]).toEqual({ type: "text", text: "Answer" })
|
||||
})
|
||||
|
||||
test("does not filter for non-anthropic providers", () => {
|
||||
const openaiModel = {
|
||||
...anthropicModel,
|
||||
|
||||
Reference in New Issue
Block a user