@@ -1172,15 +1172,17 @@ def run_task(self, in_chat: bool = True, stream: bool = True,
11721172 else :
11731173 # generate picture
11741174 try :
1175- if chart [ 'type' ] != 'table' :
1175+ if chart . get ( 'type' ) != 'table' :
11761176 yield '### generated chart picture\n \n '
1177- image_url = request_picture (self .record .chat_id , self .record .id , chart ,
1178- format_json_data (result ))
1177+ image_url , error = request_picture (self .record .chat_id , self .record .id , chart ,
1178+ format_json_data (result ))
11791179 SQLBotLogUtil .info (image_url )
11801180 if stream :
1181- yield f'![{ chart [ "type" ] } ]({ image_url } )'
1181+ yield f''
11821182 else :
11831183 json_result ['image_url' ] = image_url
1184+ if error is not None :
1185+ raise error
11841186 except Exception as e :
11851187 if stream :
11861188 raise e
@@ -1207,7 +1209,8 @@ def run_task(self, in_chat: bool = True, stream: bool = True,
12071209 yield 'data:' + orjson .dumps ({'content' : error_msg , 'type' : 'error' }).decode () + '\n \n '
12081210 else :
12091211 if stream :
1210- yield f'> ❌ **ERROR**\n \n > \n \n > { error_msg } 。'
1212+ yield f'❌ **ERROR:**\n '
1213+ yield f'> { error_msg } \n '
12111214 else :
12121215 json_result ['success' ] = False
12131216 json_result ['message' ] = error_msg
@@ -1327,19 +1330,21 @@ def run_analysis_or_predict_task(self, action_type: str, in_chat: bool = True, s
13271330
13281331 # generate picture
13291332 try :
1330- if chart [ 'type' ] != 'table' :
1333+ if chart . get ( 'type' ) != 'table' :
13311334 yield '### generated chart picture\n \n '
13321335
13331336 _data = get_chat_chart_data (_session , self .record .id )
1334- _data ['data' ] = _data [ 'data' ] + predict_data
1337+ _data ['data' ] = _data . get ( 'data' ) + predict_data
13351338
1336- image_url = request_picture (self .record .chat_id , self .record .id , chart ,
1337- format_json_data (_data ))
1339+ image_url , error = request_picture (self .record .chat_id , self .record .id , chart ,
1340+ format_json_data (_data ))
13381341 SQLBotLogUtil .info (image_url )
13391342 if stream :
1340- yield f'![{ chart [ "type" ] } ]({ image_url } )'
1343+ yield f''
13411344 else :
13421345 json_result ['image_url' ] = image_url
1346+ if error is not None :
1347+ raise error
13431348 except Exception as e :
13441349 if stream :
13451350 raise e
@@ -1360,6 +1365,7 @@ def run_analysis_or_predict_task(self, action_type: str, in_chat: bool = True, s
13601365 if not stream :
13611366 yield json_result
13621367 except Exception as e :
1368+ traceback .print_exc ()
13631369 error_msg : str
13641370 if isinstance (e , SingleMessageError ):
13651371 error_msg = str (e )
@@ -1371,7 +1377,8 @@ def run_analysis_or_predict_task(self, action_type: str, in_chat: bool = True, s
13711377 yield 'data:' + orjson .dumps ({'content' : error_msg , 'type' : 'error' }).decode () + '\n \n '
13721378 else :
13731379 if stream :
1374- yield f'> ❌ **ERROR**\n \n > \n \n > { error_msg } 。'
1380+ yield f'❌ **ERROR:**\n '
1381+ yield f'> { error_msg } \n '
13751382 else :
13761383 json_result ['success' ] = False
13771384 json_result ['message' ] = error_msg
@@ -1451,16 +1458,20 @@ def request_picture(chat_id: int, record_id: int, chart: dict, data: dict):
14511458
14521459 request_obj = {
14531460 "path" : os .path .join (settings .MCP_IMAGE_PATH , file_name ),
1454- "type" : chart [ 'type' ] ,
1461+ "type" : chart . get ( 'type' ) ,
14551462 "data" : orjson .dumps (data .get ('data' ) if data .get ('data' ) else []).decode (),
14561463 "axis" : orjson .dumps (axis ).decode (),
14571464 }
14581465
1459- requests .post (url = settings .MCP_IMAGE_HOST , json = request_obj )
1466+ _error = None
1467+ try :
1468+ requests .post (url = settings .MCP_IMAGE_HOST , json = request_obj , timeout = settings .SERVER_IMAGE_TIMEOUT )
1469+ except Exception as e :
1470+ _error = e
14601471
14611472 request_path = urllib .parse .urljoin (settings .SERVER_IMAGE_HOST , f"{ file_name } .png" )
14621473
1463- return request_path
1474+ return request_path , _error
14641475
14651476
14661477def get_token_usage (chunk : BaseMessageChunk , token_usage : dict = None ):
0 commit comments