4949from common .core .deps import CurrentAssistant , CurrentUser
5050from common .error import SingleMessageError , SQLBotDBError , ParseSQLResultError , SQLBotDBConnectionError
5151from common .utils .data_format import DataFormat
52+ from common .utils .locale import I18n , I18nHelper
5253from common .utils .utils import SQLBotLogUtil , extract_nested_json , prepare_for_orjson
5354
5455warnings .filterwarnings ("ignore" )
6263
6364session_maker = scoped_session (sessionmaker (bind = engine , class_ = Session ))
6465
66+ i18n = I18n ()
67+
6568
6669class LLMService :
6770 ds : CoreDatasource
@@ -86,6 +89,8 @@ class LLMService:
8689 chunk_list : List [str ] = []
8790 future : Future
8891
92+ trans : I18nHelper = None
93+
8994 last_execute_sql_error : str = None
9095 articles_number : int = 4
9196
@@ -125,6 +130,7 @@ def __init__(self, session: Session, current_user: CurrentUser, chat_question: C
125130 self .change_title = not get_chat_brief_generate (session = session , chat_id = chat_id )
126131
127132 chat_question .lang = get_lang_name (current_user .language )
133+ self .trans = i18n (lang = current_user .language )
128134
129135 self .ds = (
130136 ds if isinstance (ds , AssistantOutDsSchema ) else CoreDatasource (** ds .model_dump ())) if ds else None
@@ -972,7 +978,7 @@ def run_task(self, in_chat: bool = True, stream: bool = True,
972978 {'type' : 'question' , 'question' : self .get_record ().question }).decode () + '\n \n '
973979 else :
974980 if stream :
975- yield '> ID: ' + str (self .get_record ().id ) + '\n '
981+ yield '> ' + self . trans ( 'i18n_chat.record_id_in_mcp' ) + str (self .get_record ().id ) + '\n '
976982 yield '> ' + self .get_record ().question + '\n \n '
977983 if not stream :
978984 json_result ['record_id' ] = self .get_record ().id
@@ -1173,7 +1179,7 @@ def run_task(self, in_chat: bool = True, stream: bool = True,
11731179 # generate picture
11741180 try :
11751181 if chart .get ('type' ) != 'table' :
1176- yield '### generated chart picture\n \n '
1182+ # yield '### generated chart picture\n\n'
11771183 image_url , error = request_picture (self .record .chat_id , self .record .id , chart ,
11781184 format_json_data (result ))
11791185 SQLBotLogUtil .info (image_url )
@@ -1185,6 +1191,8 @@ def run_task(self, in_chat: bool = True, stream: bool = True,
11851191 raise error
11861192 except Exception as e :
11871193 if stream :
1194+ if chart .get ('type' ) != 'table' :
1195+ yield 'generate or fetch chart picture error.\n \n '
11881196 raise e
11891197
11901198 if not stream :
@@ -1263,7 +1271,7 @@ def run_analysis_or_predict_task(self, action_type: str, in_chat: bool = True, s
12631271 yield 'data:' + orjson .dumps ({'type' : 'id' , 'id' : self .get_record ().id }).decode () + '\n \n '
12641272 else :
12651273 if stream :
1266- yield '> ID: ' + str (self .get_record ().id ) + '\n '
1274+ yield '> ' + self . trans ( 'i18n_chat.record_id_in_mcp' ) + str (self .get_record ().id ) + '\n '
12671275 yield '> ' + self .get_record ().question + '\n \n '
12681276 if not stream :
12691277 json_result ['record_id' ] = self .get_record ().id
@@ -1331,7 +1339,7 @@ def run_analysis_or_predict_task(self, action_type: str, in_chat: bool = True, s
13311339 # generate picture
13321340 try :
13331341 if chart .get ('type' ) != 'table' :
1334- yield '### generated chart picture\n \n '
1342+ # yield '### generated chart picture\n\n'
13351343
13361344 _data = get_chat_chart_data (_session , self .record .id )
13371345 _data ['data' ] = _data .get ('data' ) + predict_data
@@ -1347,6 +1355,8 @@ def run_analysis_or_predict_task(self, action_type: str, in_chat: bool = True, s
13471355 raise error
13481356 except Exception as e :
13491357 if stream :
1358+ if chart .get ('type' ) != 'table' :
1359+ yield 'generate or fetch chart picture error.\n \n '
13501360 raise e
13511361 else :
13521362 if in_chat :
0 commit comments