Skip to content

Commit 30b61e7

Browse files
committed
update code & add try-except in runner
1 parent 77d090d commit 30b61e7

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

veadk/runner.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ def _build_tos_object_key(
9898
object_key: str = f"{app_name}-{user_id}-{session_id}/{timestamp}-{file_name}"
9999
return object_key
100100

101+
def _upload_to_tos(self, data: Union[str, bytes], object_key: str):
102+
tos_client = TOSClient()
103+
asyncio.create_task(tos_client.upload(object_key, data))
104+
tos_client.close()
105+
return
106+
101107
def _convert_messages(self, messages, session_id) -> list:
102108
if isinstance(messages, str):
103109
messages = [types.Content(role="user", parts=[types.Part(text=messages)])]
@@ -106,14 +112,14 @@ def _convert_messages(self, messages, session_id) -> list:
106112
"The MediaMessage only supports PNG format file for now."
107113
)
108114
data = read_png_to_bytes(messages.media)
109-
object_key = messages.media
110-
if self.agent.tracers:
111-
tos_client = TOSClient()
115+
try:
112116
object_key = self._build_tos_object_key(
113117
self.user_id, self.app_name, session_id, messages.media
114118
)
115-
asyncio.create_task(tos_client.upload(object_key, data))
116-
tos_client.close()
119+
self._upload_to_tos(data, object_key)
120+
except Exception as e:
121+
logger.error(f"Upload to TOS failed: {e}")
122+
object_key = None
117123

118124
messages = [
119125
types.Content(

0 commit comments

Comments
 (0)