Encode an image file to base64 and determine its MIME type. Args: image_path (str): Path to the image file Returns: tuple: (base64_encoded_string, mime_type)
(image_path: str)
| 47 | load_environment() |
| 48 | |
| 49 | def encode_image_file(image_path: str) -> tuple[str, str]: |
| 50 | """ |
| 51 | Encode an image file to base64 and determine its MIME type. |
| 52 | |
| 53 | Args: |
| 54 | image_path (str): Path to the image file |
| 55 | |
| 56 | Returns: |
| 57 | tuple: (base64_encoded_string, mime_type) |
| 58 | """ |
| 59 | mime_type, _ = mimetypes.guess_type(image_path) |
| 60 | if not mime_type: |
| 61 | mime_type = 'image/png' # Default to PNG if type cannot be determined |
| 62 | |
| 63 | with open(image_path, "rb") as image_file: |
| 64 | encoded_string = base64.b64encode(image_file.read()).decode('utf-8') |
| 65 | |
| 66 | return encoded_string, mime_type |
| 67 | |
| 68 | def create_llm_client(provider="openai"): |
| 69 | if provider == "openai": |