Skip to content

Commit 9e8f8be

Browse files
committed
Handle image blocks when switching to a model that doesn't support them
1 parent 66055f1 commit 9e8f8be

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/core/Cline.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,8 +799,30 @@ export class Cline {
799799
}
800800
}
801801

802-
// Convert to Anthropic.MessageParam by spreading only the API-required properties
803-
const cleanConversationHistory = this.apiConversationHistory.map(({ role, content }) => ({ role, content }))
802+
// Clean conversation history by:
803+
// 1. Converting to Anthropic.MessageParam by spreading only the API-required properties
804+
// 2. Converting image blocks to text descriptions if model doesn't support images
805+
const cleanConversationHistory = this.apiConversationHistory.map(({ role, content }) => {
806+
// Handle array content (could contain image blocks)
807+
if (Array.isArray(content)) {
808+
if (!this.api.getModel().info.supportsImages) {
809+
// Convert image blocks to text descriptions
810+
content = content.map(block => {
811+
if (block.type === 'image') {
812+
// Convert image blocks to text descriptions
813+
// Note: We can't access the actual image content/url due to API limitations,
814+
// but we can indicate that an image was present in the conversation
815+
return {
816+
type: 'text',
817+
text: '[Referenced image in conversation]'
818+
};
819+
}
820+
return block;
821+
});
822+
}
823+
}
824+
return { role, content }
825+
})
804826
const stream = this.api.createMessage(systemPrompt, cleanConversationHistory)
805827
const iterator = stream[Symbol.asyncIterator]()
806828

0 commit comments

Comments
 (0)