| 3123 | |
| 3124 | @staticmethod |
| 3125 | def _load_image(image_url: str) -> bytes: |
| 3126 | # TODO: Add Pillow support for other image formats beyond (jpg, png) |
| 3127 | if image_url.startswith("data:"): |
| 3128 | import base64 |
| 3129 | |
| 3130 | image_bytes = base64.b64decode(image_url.split(",")[1]) |
| 3131 | return image_bytes |
| 3132 | else: |
| 3133 | import urllib.request |
| 3134 | |
| 3135 | with urllib.request.urlopen(image_url) as f: |
| 3136 | image_bytes = f.read() |
| 3137 | return image_bytes |
| 3138 | |
| 3139 | @staticmethod |
| 3140 | def get_image_urls(messages: List[llama_types.ChatCompletionRequestMessage]): |