Skip to content

Commit ddcfa71

Browse files
alcholiclgalcholiclg
andauthored
Fix: return type mismatch (#664)
Co-authored-by: alcholiclg <ligongshengzju@foxmail.com>
1 parent a89e7c7 commit ddcfa71

File tree

3 files changed

+5
-44
lines changed

3 files changed

+5
-44
lines changed

ms_agent/tools/docling/doc_loader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def html_handle_figure(self, element: Tag, doc: DoclingDocument) -> None:
4141

4242
if img_url:
4343
if img_url.startswith('data:'):
44-
img_pil, ext = load_image_from_uri_to_pil(img_url)
44+
img_pil = load_image_from_uri_to_pil(img_url)
4545
else:
4646
if not img_url.startswith('http'):
4747
img_url = validate_url(img_url=img_url, backend=self)
@@ -98,7 +98,7 @@ def html_handle_image(self, element: Tag, doc: DoclingDocument) -> None:
9898

9999
if img_url:
100100
if img_url.startswith('data:'):
101-
img_pil, ext = load_image_from_uri_to_pil(img_url)
101+
img_pil = load_image_from_uri_to_pil(img_url)
102102
else:
103103
if not img_url.startswith('http'):
104104
img_url = validate_url(img_url=img_url, backend=self)

ms_agent/utils/download.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

ms_agent/utils/utils.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def load_image_from_url_to_pil(url: str) -> 'Image.Image':
334334
return None
335335

336336

337-
def load_image_from_uri_to_pil(uri: str) -> tuple:
337+
def load_image_from_uri_to_pil(uri: str) -> 'Image.Image':
338338
"""
339339
Load image from URI as a PIL Image object and extract its format extension.
340340
URI format: data:[<mime>][;base64],<encoded>
@@ -352,18 +352,16 @@ def load_image_from_uri_to_pil(uri: str) -> tuple:
352352
raw = base64.b64decode(encoded)
353353
else:
354354
raw = encoded.encode('utf-8')
355-
m = re.match(r'data:(image/[^;]+)', header)
356-
ext = m.group(1).split('/')[-1] if m else 'bin'
357355
img = Image.open(BytesIO(raw))
358-
return img, ext
356+
return img
359357
except ValueError as e:
360358
print(f'Error parsing URI format: {e}')
361359
return None
362360
except base64.binascii.Error as e:
363361
print(f'Error decoding base64 data: {e}')
364362
return None
365363
except IOError as e:
366-
print(f'Error opening image: {e}')
364+
print(f'Error opening image with PIL: {e}')
367365
return None
368366
except Exception as e:
369367
print(f'Unexpected error loading image from URI: {e}')

0 commit comments

Comments
 (0)