@@ -111,7 +111,8 @@ def __init__(self, session: Session, current_user: CurrentUser, chat_question: C
111111 _ds = session .get (CoreDatasource , chat_question .datasource_id )
112112 if _ds :
113113 if _ds .oid != current_user .oid :
114- raise SingleMessageError (f"Datasource with id { chat_question .datasource_id } does not belong to current workspace" )
114+ raise SingleMessageError (
115+ f"Datasource with id { chat_question .datasource_id } does not belong to current workspace" )
115116 chat .datasource = _ds .id
116117 chat .engine_type = _ds .type_name
117118 # save chat
@@ -410,7 +411,8 @@ def generate_recommend_questions_task(self, _session: Session):
410411 reasoning_content = full_thinking_text ,
411412 token_usage = token_usage )
412413 self .record = save_recommend_question_answer (session = _session , record_id = self .record .id ,
413- answer = {'content' : full_guess_text }, articles_number = self .articles_number )
414+ answer = {'content' : full_guess_text },
415+ articles_number = self .articles_number )
414416
415417 yield {'recommended_question' : self .record .recommended_question }
416418
@@ -716,9 +718,9 @@ def generate_assistant_filter(self, _session: Session, sql, tables: List):
716718 return None
717719 return self .build_table_filter (session = _session , sql = sql , filters = filters )
718720
719- def generate_chart (self , _session : Session , chart_type : Optional [str ] = '' ):
721+ def generate_chart (self , _session : Session , chart_type : Optional [str ] = '' , schema : Optional [ str ] = '' ):
720722 # append current question
721- self .chart_message .append (HumanMessage (self .chat_question .chart_user_question (chart_type )))
723+ self .chart_message .append (HumanMessage (self .chat_question .chart_user_question (chart_type , schema )))
722724
723725 self .current_logs [OperationEnum .GENERATE_CHART ] = start_log (session = _session ,
724726 ai_modal_id = self .chat_question .ai_modal_id ,
@@ -1079,9 +1081,9 @@ def run_task(self, in_chat: bool = True, stream: bool = True,
10791081 sqlbot_temp_sql_text = None
10801082 assistant_dynamic_sql = None
10811083 # row permission
1084+ sql , tables = self .check_sql (res = full_sql_text )
10821085 if ((not self .current_assistant or is_page_embedded ) and is_normal_user (
10831086 self .current_user )) or use_dynamic_ds :
1084- sql , tables = self .check_sql (res = full_sql_text )
10851087 sql_result = None
10861088
10871089 if use_dynamic_ds :
@@ -1167,7 +1169,16 @@ def run_task(self, in_chat: bool = True, stream: bool = True,
11671169 return
11681170
11691171 # generate chart
1170- chart_res = self .generate_chart (_session , chart_type )
1172+ used_tables_schema = self .out_ds_instance .get_db_schema (
1173+ self .ds .id , self .chat_question .question , embedding = False ,
1174+ table_list = tables ) if self .out_ds_instance else get_table_schema (
1175+ session = _session ,
1176+ current_user = self .current_user ,
1177+ ds = self .ds ,
1178+ question = self .chat_question .question ,
1179+ embedding = False , table_list = tables )
1180+ SQLBotLogUtil .info ('used_tables_schema: \n ' + used_tables_schema )
1181+ chart_res = self .generate_chart (_session , chart_type , used_tables_schema )
11711182 full_chart_text = ''
11721183 for chunk in chart_res :
11731184 full_chart_text += chunk .get ('content' )
@@ -1482,7 +1493,7 @@ def request_picture(chat_id: int, record_id: int, chart: dict, data: dict):
14821493 y = None
14831494 series = None
14841495 multi_quota_fields = []
1485- multi_quota_name = None
1496+ multi_quota_name = None
14861497
14871498 if chart .get ('axis' ):
14881499 axis_data = chart .get ('axis' )
0 commit comments