From 9e8f8be5e1b1d7d1ce5628890aabab1f57112b90 Mon Sep 17 00:00:00 2001 From: Matt Rubens Date: Tue, 7 Jan 2025 23:36:28 -0500 Subject: [PATCH] Handle image blocks when switching to a model that doesn't support them --- src/core/Cline.ts | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/core/Cline.ts b/src/core/Cline.ts index 840caff..9f650c2 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -799,8 +799,30 @@ export class Cline { } } - // Convert to Anthropic.MessageParam by spreading only the API-required properties - const cleanConversationHistory = this.apiConversationHistory.map(({ role, content }) => ({ role, content })) + // Clean conversation history by: + // 1. Converting to Anthropic.MessageParam by spreading only the API-required properties + // 2. Converting image blocks to text descriptions if model doesn't support images + const cleanConversationHistory = this.apiConversationHistory.map(({ role, content }) => { + // Handle array content (could contain image blocks) + if (Array.isArray(content)) { + if (!this.api.getModel().info.supportsImages) { + // Convert image blocks to text descriptions + content = content.map(block => { + if (block.type === 'image') { + // Convert image blocks to text descriptions + // Note: We can't access the actual image content/url due to API limitations, + // but we can indicate that an image was present in the conversation + return { + type: 'text', + text: '[Referenced image in conversation]' + }; + } + return block; + }); + } + } + return { role, content } + }) const stream = this.api.createMessage(systemPrompt, cleanConversationHistory) const iterator = stream[Symbol.asyncIterator]()