feat(ai): add vision support for multimodal messages#683
Merged
willgriffin merged 1 commit intomainfrom Dec 19, 2025
Merged
Conversation
Add support for vision-capable LLMs by extending AIMessage.content to accept
both simple strings and multimodal content arrays (ContentPart[]).
Changes:
- Add ContentPart types (TextContentPart, ImageContentPart) for multimodal messages
- Add extractTextContent() helper function for backward compatibility
- Update AIMessage.content type to accept string | ContentPart[]
- Update OpenAI provider to properly map ContentPart arrays to OpenAI format
- Update all other providers (Anthropic, Bedrock, Claude-CLI, Gemini, HuggingFace)
to use extractTextContent() for backward compatibility
This enables usage like:
```typescript
await ai.chat([
{
role: 'user',
content: [
{ type: 'text', text: 'What is in this image?' },
{ type: 'image_url', image_url: { url: 'data:image/png;base64,...' } }
]
}
]);
```
Required for @happyvertical/ocr LiteLLM provider vision-based OCR.
Contributor
📦 Version Bump PreviewWhen this PR is merged, packages will receive a minor What happens on merge?
No manual intervention needed! 🎉 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add support for vision-capable LLMs by extending
AIMessage.contentto accept both simple strings and multimodal content arrays (ContentPart[]).Changes:
ContentParttypes (TextContentPart,ImageContentPart) for multimodal messagesextractTextContent()helper function for backward compatibilityAIMessage.contenttype to acceptstring | ContentPart[]ContentPartarrays to OpenAI formatextractTextContent()for backward compatibilityUsage
This enables vision-capable models to accept images inline:
Motivation
Required for
@happyvertical/ocrLiteLLM provider which uses vision-capable LLMs for OCR text extraction.See: happyvertical/ocr#21
Test plan