| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c6e2bdb commit a9ddfde
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,7 +52,28 @@ function normalizeMessages( | |||
| 52 | 52 | ): ModelMessage[] { | |
| 53 | 53 | // Anthropic rejects messages with empty content - filter out empty string messages | |
| 54 | 54 | // and remove empty text/reasoning parts from array content | |
| 55 | - if (model.api.npm === "@ai-sdk/anthropic" || model.api.npm === "@ai-sdk/amazon-bedrock") { | ||
| 55 | + if (model.api.npm === "@ai-sdk/anthropic") { | ||
| 56 | + msgs = msgs | ||
| 57 | + .map((msg) => { | ||
| 58 | + if (typeof msg.content === "string") { | ||
| 59 | + if (msg.content === "") return undefined | ||
| 60 | + return msg | ||
| 61 | + } | ||
| 62 | + if (!Array.isArray(msg.content)) return msg | ||
| 63 | + const filtered = msg.content.filter((part) => { | ||
| 64 | + if (part.type === "text" || part.type === "reasoning") { | ||
| 65 | + return part.text !== "" | ||
| 66 | + } | ||
| 67 | + return true | ||
| 68 | + }) | ||
| 69 | + if (filtered.length === 0) return undefined | ||
| 70 | + return { ...msg, content: filtered } | ||
| 71 | + }) | ||
| 72 | + .filter((msg): msg is ModelMessage => msg !== undefined && msg.content !== "") | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + // Bedrock specific transforms | ||
| 76 | + if (model.api.npm === "@ai-sdk/amazon-bedrock") { | ||
| 56 | 77 | msgs = msgs | |
| 57 | 78 | .map((msg) => { | |
| 58 | 79 | if (typeof msg.content === "string") { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments