Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ format:

unit-tests:
pytest libs/core/tests/unit_tests

integration-tests:
pytest libs/llmstudio/tests/integration_tests
17 changes: 11 additions & 6 deletions libs/core/llmstudio_core/providers/bedrock_converse.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,17 +335,22 @@ def _process_messages(
return messages, system_prompt

@staticmethod
def _base64_to_bytes(image_url: str) -> bytes:
def _b64_data_url_to_bytes(b64_data_url: str) -> bytes:
"""
Extracts and decodes Base64 image data from a 'data:image/...;base64,...' URL.
Extracts and decodes Base64 image data from a 'data:image/...;base64,...' data URL.
Returns the raw image bytes.
"""
if not image_url.startswith("data:image/"):
if not b64_data_url.startswith("data:image/"):
raise ValueError("Invalid Base64 image URL")

base64_data = re.sub(r"^data:image/[^;]+;base64,", "", image_url)
base64_data = re.sub(r"^data:image/[^;]+;base64,", "", b64_data_url)

return base64.b64decode(base64_data)
try:
return base64.b64decode(base64_data)
except Exception as e:
raise ValueError(
f"Failed to decode Base64: {e} ; For Base64 Data Url: {b64_data_url}"
)

@staticmethod
def _get_img_format_from_bytes(image_bytes: bytes) -> str:
Expand Down Expand Up @@ -377,7 +382,7 @@ def _get_image_bytes(image_url: str) -> bytes:
- If it's a normal URL, downloads and encodes the image in Base64.
"""
if image_url.startswith("data:image/"):
return BedrockConverseProvider._base64_to_bytes(image_url)
return BedrockConverseProvider._b64_data_url_to_bytes(image_url)

elif image_url.startswith(("http://", "https://")):
response = requests.get(image_url)
Expand Down