(messages: ApiMessage[], apiHandler: ApiHandler)
| 4 | |
| 5 | /* Removes image blocks from messages if they are not supported by the Api Handler */ |
| 6 | export function maybeRemoveImageBlocks(messages: ApiMessage[], apiHandler: ApiHandler): ApiMessage[] { |
| 7 | // Check model capability ONCE instead of for every message |
| 8 | const supportsImages = apiHandler.getModel().info.supportsImages |
| 9 | |
| 10 | return messages.map((message) => { |
| 11 | // Handle array content (could contain image blocks). |
| 12 | let { content } = message |
| 13 | if (Array.isArray(content)) { |
| 14 | if (!supportsImages) { |
| 15 | // Convert image blocks to text descriptions. |
| 16 | content = content.map((block) => { |
| 17 | if (block.type === "image") { |
| 18 | // Convert image blocks to text descriptions. |
| 19 | // Note: We can't access the actual image content/url due to API limitations, |
| 20 | // but we can indicate that an image was present in the conversation. |
| 21 | return { |
| 22 | type: "text", |
| 23 | text: "[Referenced image in conversation]", |
| 24 | } |
| 25 | } |
| 26 | return block |
| 27 | }) |
| 28 | } |
| 29 | } |
| 30 | return { ...message, content } |
| 31 | }) |
| 32 | } |
no test coverage detected