@@ -67,8 +67,13 @@ def get_chat_predict_data(session: SessionDep, chart_record_id: int):
67
67
return {}
68
68
69
69
70
+ def get_chat_with_records_with_data (session : SessionDep , chart_id : int , current_user : CurrentUser ,
71
+ current_assistant : CurrentAssistant ) -> ChatInfo :
72
+ return get_chat_with_records (session , chart_id , current_user , current_assistant , True )
73
+
74
+
70
75
def get_chat_with_records (session : SessionDep , chart_id : int , current_user : CurrentUser ,
71
- current_assistant : CurrentAssistant ) -> ChatInfo :
76
+ current_assistant : CurrentAssistant , with_data : bool = False ) -> ChatInfo :
72
77
chat = session .get (Chat , chart_id )
73
78
if not chat :
74
79
raise Exception (f"Chat with id { chart_id } not found" )
@@ -96,18 +101,39 @@ def get_chat_with_records(session: SessionDep, chart_id: int, current_user: Curr
96
101
ChatRecord .recommended_question , ChatRecord .first_chat ,
97
102
ChatRecord .finish , ChatRecord .error ).where (
98
103
and_ (ChatRecord .create_by == current_user .id , ChatRecord .chat_id == chart_id )).order_by (ChatRecord .create_time )
104
+ if with_data :
105
+ stmt = select (ChatRecord .id , ChatRecord .chat_id , ChatRecord .create_time , ChatRecord .finish_time ,
106
+ ChatRecord .question , ChatRecord .sql_answer , ChatRecord .sql ,
107
+ ChatRecord .chart_answer , ChatRecord .chart , ChatRecord .analysis , ChatRecord .predict ,
108
+ ChatRecord .datasource_select_answer , ChatRecord .analysis_record_id , ChatRecord .predict_record_id ,
109
+ ChatRecord .recommended_question , ChatRecord .first_chat ,
110
+ ChatRecord .finish , ChatRecord .error , ChatRecord .data , ChatRecord .predict_data ).where (
111
+ and_ (ChatRecord .create_by == current_user .id , ChatRecord .chat_id == chart_id )).order_by (
112
+ ChatRecord .create_time )
113
+
99
114
result = session .execute (stmt ).all ()
100
115
record_list : list [ChatRecord ] = []
101
116
for row in result :
102
- record_list .append (
103
- ChatRecord (id = row .id , chat_id = row .chat_id , create_time = row .create_time , finish_time = row .finish_time ,
104
- question = row .question , sql_answer = row .sql_answer , sql = row .sql ,
105
- chart_answer = row .chart_answer , chart = row .chart ,
106
- analysis = row .analysis , predict = row .predict ,
107
- datasource_select_answer = row .datasource_select_answer ,
108
- analysis_record_id = row .analysis_record_id , predict_record_id = row .predict_record_id ,
109
- recommended_question = row .recommended_question , first_chat = row .first_chat ,
110
- finish = row .finish , error = row .error ))
117
+ if not with_data :
118
+ record_list .append (
119
+ ChatRecord (id = row .id , chat_id = row .chat_id , create_time = row .create_time , finish_time = row .finish_time ,
120
+ question = row .question , sql_answer = row .sql_answer , sql = row .sql ,
121
+ chart_answer = row .chart_answer , chart = row .chart ,
122
+ analysis = row .analysis , predict = row .predict ,
123
+ datasource_select_answer = row .datasource_select_answer ,
124
+ analysis_record_id = row .analysis_record_id , predict_record_id = row .predict_record_id ,
125
+ recommended_question = row .recommended_question , first_chat = row .first_chat ,
126
+ finish = row .finish , error = row .error ))
127
+ else :
128
+ record_list .append (
129
+ ChatRecord (id = row .id , chat_id = row .chat_id , create_time = row .create_time , finish_time = row .finish_time ,
130
+ question = row .question , sql_answer = row .sql_answer , sql = row .sql ,
131
+ chart_answer = row .chart_answer , chart = row .chart ,
132
+ analysis = row .analysis , predict = row .predict ,
133
+ datasource_select_answer = row .datasource_select_answer ,
134
+ analysis_record_id = row .analysis_record_id , predict_record_id = row .predict_record_id ,
135
+ recommended_question = row .recommended_question , first_chat = row .first_chat ,
136
+ finish = row .finish , error = row .error , data = row .data , predict_data = row .predict_data ))
111
137
112
138
result = list (map (format_record , record_list ))
113
139
0 commit comments