Handle image blocks when switching to a model that doesn't support them

This commit is contained in:
Matt Rubens
2025-01-07 23:36:28 -05:00
parent 66055f10a2
commit 9e8f8be5e1

View File

@@ -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]()