|
14 | 14 | ContentToolResult, |
15 | 15 | ContentUnion, |
16 | 16 | ) |
| 17 | +from ._content_pdf import parse_data_url |
17 | 18 | from ._turn import Turn |
18 | 19 |
|
19 | 20 | if TYPE_CHECKING: |
@@ -166,7 +167,9 @@ def chatlas_content_as_inspect(content: ContentUnion) -> InspectContent: |
166 | 167 | elif isinstance(content, ContentImageRemote): |
167 | 168 | return itool.ContentImage(image=content.url, detail=content.detail) |
168 | 169 | elif isinstance(content, ContentImageInline): |
169 | | - return itool.ContentImage(image=content.data or "", detail="auto") |
| 170 | + # Reconstruct the data URL from the base64 data and content type |
| 171 | + data_url = f"data:{content.image_content_type};base64,{content.data or ''}" |
| 172 | + return itool.ContentImage(image=data_url, detail="auto") |
170 | 173 | elif isinstance(content, ContentPDF): |
171 | 174 | return itool.ContentDocument( |
172 | 175 | document=base64.b64encode(content.data).decode("ascii"), |
@@ -199,11 +202,11 @@ def inspect_content_as_chatlas(content: str | InspectContent) -> Content: |
199 | 202 | if content.image.startswith("http://") or content.image.startswith("https://"): |
200 | 203 | return ContentImageRemote(url=content.image, detail=content.detail) |
201 | 204 | else: |
202 | | - # derive content_type from base64 data |
| 205 | + # Parse data URL to extract content type and base64 data |
203 | 206 | # e.g., data:image/png;base64,.... |
204 | | - content_type = content.image.split(":")[1].split(";")[0] |
| 207 | + content_type, base64_data = parse_data_url(content.image) |
205 | 208 | return ContentImageInline( |
206 | | - data=content.image, |
| 209 | + data=base64_data, |
207 | 210 | image_content_type=content_type, # type: ignore |
208 | 211 | ) |
209 | 212 | if isinstance(content, itool.ContentDocument): |
|
0 commit comments