mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-17 04:36:01 +08:00
Fix: https://github.com/langgenius/dify/issues/8190 (Update Model nam… (#8426)
Co-authored-by: Yuanbo Li <ybalbert@amazon.com>
This commit is contained in:
parent
6f7625fa47
commit
b6ad7a1e06
@ -1,8 +1,8 @@
|
|||||||
# standard import
|
# standard import
|
||||||
import base64
|
import base64
|
||||||
import io
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import mimetypes
|
||||||
from collections.abc import Generator
|
from collections.abc import Generator
|
||||||
from typing import Optional, Union, cast
|
from typing import Optional, Union, cast
|
||||||
|
|
||||||
@ -17,7 +17,6 @@ from botocore.exceptions import (
|
|||||||
ServiceNotInRegionError,
|
ServiceNotInRegionError,
|
||||||
UnknownServiceError,
|
UnknownServiceError,
|
||||||
)
|
)
|
||||||
from PIL.Image import Image
|
|
||||||
|
|
||||||
# local import
|
# local import
|
||||||
from core.model_runtime.callbacks.base_callback import Callback
|
from core.model_runtime.callbacks.base_callback import Callback
|
||||||
@ -443,8 +442,9 @@ class BedrockLargeLanguageModel(LargeLanguageModel):
|
|||||||
try:
|
try:
|
||||||
url = message_content.data
|
url = message_content.data
|
||||||
image_content = requests.get(url).content
|
image_content = requests.get(url).content
|
||||||
with Image.open(io.BytesIO(image_content)) as img:
|
if "?" in url:
|
||||||
mime_type = f"image/{img.format.lower()}"
|
url = url.split("?")[0]
|
||||||
|
mime_type, _ = mimetypes.guess_type(url)
|
||||||
base64_data = base64.b64encode(image_content).decode("utf-8")
|
base64_data = base64.b64encode(image_content).decode("utf-8")
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
raise ValueError(f"Failed to fetch image data from url {message_content.data}, {ex}")
|
raise ValueError(f"Failed to fetch image data from url {message_content.data}, {ex}")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user