|
@@ -1,7 +1,7 @@
|
|
|
import base64
|
|
|
+import io
|
|
|
import json
|
|
|
import logging
|
|
|
-import mimetypes
|
|
|
from collections.abc import Generator
|
|
|
from typing import Optional, Union, cast
|
|
|
|
|
@@ -12,6 +12,7 @@ import google.generativeai.client as client
|
|
|
import requests
|
|
|
from google.generativeai.types import ContentType, GenerateContentResponse, HarmBlockThreshold, HarmCategory
|
|
|
from google.generativeai.types.content_types import to_part
|
|
|
+from PIL import Image
|
|
|
|
|
|
from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta
|
|
|
from core.model_runtime.entities.message_entities import (
|
|
@@ -371,7 +372,8 @@ class GoogleLargeLanguageModel(LargeLanguageModel):
|
|
|
# fetch image data from url
|
|
|
try:
|
|
|
image_content = requests.get(message_content.data).content
|
|
|
- mime_type, _ = mimetypes.guess_type(message_content.data)
|
|
|
+ with Image.open(io.BytesIO(image_content)) as img:
|
|
|
+ mime_type = f"image/{img.format.lower()}"
|
|
|
base64_data = base64.b64encode(image_content).decode('utf-8')
|
|
|
except Exception as ex:
|
|
|
raise ValueError(f"Failed to fetch image data from url {message_content.data}, {ex}")
|