Skip to content

Commit 8cde746

Browse files
committed
fix(integrations): using common function to parse data URIs
1 parent 97cc614 commit 8cde746

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

sentry_sdk/integrations/litellm.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from sentry_sdk.ai.monitoring import record_token_usage
77
from sentry_sdk.ai.utils import (
88
get_start_span_function,
9+
parse_data_uri,
910
set_data_normalized,
1011
truncate_and_annotate_messages,
1112
)
@@ -83,17 +84,18 @@ def _map_item(item: "Dict[str, Any]") -> "Dict[str, Any]":
8384
if item.get("type") == "image_url":
8485
image_url = item.get("image_url") or {}
8586
url = image_url.get("url", "")
86-
if url.startswith("data:") and ";base64," in url:
87-
parts = url.split(";base64,", 1)
88-
# Remove "data:" prefix (5 chars) to get proper MIME type
89-
mime_type = parts[0][5:]
90-
return {
91-
"type": "blob",
92-
"modality": "image",
93-
"mime_type": mime_type,
94-
"content": parts[1],
95-
}
96-
elif url:
87+
if url.startswith("data:"):
88+
try:
89+
mime_type, content = parse_data_uri(url)
90+
return {
91+
"type": "blob",
92+
"modality": "image",
93+
"mime_type": mime_type,
94+
"content": content,
95+
}
96+
except ValueError:
97+
pass
98+
if url:
9799
return {
98100
"type": "uri",
99101
"uri": url,

0 commit comments

Comments
 (0)