motleycrew.utils.image_utils
Utilities for working with images in LLM contexts.
Functions
|
Convert image bytes to PNG format if the source format is unsupported. |
|
|
|
Create a HumanMessage containing an image represented as bytes |
|
- motleycrew.utils.image_utils.convert_image_to_png(image_bytes: bytes, source_mime_type: str) Tuple[bytes, str]
Convert image bytes to PNG format if the source format is unsupported.
Uses LibreOffice for EMF/WMF (which ImageMagick can’t handle on Linux), and Wand/ImageMagick for other formats. For supported formats (JPEG, PNG, GIF, WebP), returns original bytes unchanged.
- Parameters:
image_bytes – Raw image bytes
source_mime_type – MIME type of the source image
- Returns:
Tuple of (converted_bytes, mime_type). Returns original if already supported.
- motleycrew.utils.image_utils.human_message_from_image_bytes(image_bytes: bytes, mime_type: str) HumanMessage
- motleycrew.utils.image_utils.image_file_to_bytes_and_mime_type(image_path: str) Tuple[bytes, str]
Create a HumanMessage containing an image represented as bytes
- Parameters:
image_path – Path to the local image file
- Returns:
HumanMessage containing the image content
- motleycrew.utils.image_utils.is_this_a_chart(image_bytes: bytes, mime_type: str, llm: BaseLanguageModel) bool