Skip to content

Commit 5fbd461

Browse files
authored
chore: updated b64 converse errors and naming for clarity. added make integration-tests command. (#218)
1 parent 22ef581 commit 5fbd461

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ format:
33

44
unit-tests:
55
pytest libs/core/tests/unit_tests
6+
7+
integration-tests:
8+
pytest libs/llmstudio/tests/integration_tests

libs/core/llmstudio_core/providers/bedrock_converse.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,17 +335,22 @@ def _process_messages(
335335
return messages, system_prompt
336336

337337
@staticmethod
338-
def _base64_to_bytes(image_url: str) -> bytes:
338+
def _b64_data_url_to_bytes(b64_data_url: str) -> bytes:
339339
"""
340-
Extracts and decodes Base64 image data from a 'data:image/...;base64,...' URL.
340+
Extracts and decodes Base64 image data from a 'data:image/...;base64,...' data URL.
341341
Returns the raw image bytes.
342342
"""
343-
if not image_url.startswith("data:image/"):
343+
if not b64_data_url.startswith("data:image/"):
344344
raise ValueError("Invalid Base64 image URL")
345345

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

348-
return base64.b64decode(base64_data)
348+
try:
349+
return base64.b64decode(base64_data)
350+
except Exception as e:
351+
raise ValueError(
352+
f"Failed to decode Base64: {e} ; For Base64 Data Url: {b64_data_url}"
353+
)
349354

350355
@staticmethod
351356
def _get_img_format_from_bytes(image_bytes: bytes) -> str:
@@ -377,7 +382,7 @@ def _get_image_bytes(image_url: str) -> bytes:
377382
- If it's a normal URL, downloads and encodes the image in Base64.
378383
"""
379384
if image_url.startswith("data:image/"):
380-
return BedrockConverseProvider._base64_to_bytes(image_url)
385+
return BedrockConverseProvider._b64_data_url_to_bytes(image_url)
381386

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

0 commit comments

Comments
 (0)