Skip to content

Commit 4b4bdb3

Browse files
author
liuhuiqi.7
committed
feat(arkruntime): image pre parse
feat(arkruntime): error msg
1 parent 1bcafd3 commit 4b4bdb3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

volcenginesdkarkruntime/resources/encryption.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import json
1111
import warnings
1212
from copy import deepcopy
13+
from urllib.parse import urlparse
1314
from typing import (
1415
Union,
1516
Iterable,
@@ -187,14 +188,21 @@ def _process_messages(
187188
if part.get("type", None) == "text":
188189
part["text"] = f(part["text"])
189190
elif part.get("type", None) == "image_url":
190-
if part["image_url"]["url"].startswith("data:"):
191+
parse_result = urlparse(part["image_url"]["url"])
192+
if parse_result.scheme == 'data':
191193
part["image_url"]["url"] = f(
192194
part["image_url"]["url"])
193-
else:
195+
elif parse_result.scheme == 'http' or parse_result.scheme == 'https':
194196
warnings.warn(
195197
"encryption is not supported for image url, "
196198
"please use base64 image if you want encryption"
197199
)
200+
else:
201+
raise TypeError(
202+
"encryption is not supported for image url scheme {}".format(
203+
parse_result
204+
)
205+
)
198206
else:
199207
raise TypeError(
200208
"encryption is not supported for content type {}".format(

0 commit comments

Comments
 (0)