pvanand commited on
Commit
1a030f4
·
verified ·
1 Parent(s): 410c5d9

Update rag_routerv2.py

Browse files
Files changed (1) hide show
  1. rag_routerv2.py +20 -22
rag_routerv2.py CHANGED
@@ -171,28 +171,26 @@ async def query_table(
171
 
172
  @router.get("/get_tables/{user_id}")
173
  async def get_tables(user_id: str):
174
- db = get_db()
175
- tables = db.execute('''
176
- SELECT t.*, t.created_time, GROUP_CONCAT(tf.filename) as filenames, GROUP_CONCAT(tf.file_path) as file_paths
177
- FROM tables t
178
- LEFT JOIN table_files tf ON t.table_id = tf.table_id
179
- WHERE t.user_id = ?
180
- GROUP BY t.table_id
181
- ''', (user_id,)).fetchall()
182
-
183
- result = []
184
- for table in tables:
185
- table_dict = dict(table)
186
- table_dict['files'] = [
187
- {'filename': f, 'file_path': p}
188
- for f, p in zip(
189
- table_dict.pop('filenames').split(',') if table_dict['filenames'] else [],
190
- table_dict.pop('file_paths').split(',') if table_dict['file_paths'] else []
191
- )
192
- ]
193
- result.append(table_dict)
194
-
195
- return result
196
 
197
 
198
  @router.delete("/delete_table/{table_id}")
 
171
 
172
  @router.get("/get_tables/{user_id}")
173
  async def get_tables(user_id: str):
174
+ db = get_db()
175
+ tables = db.execute('''
176
+ SELECT t.*,
177
+ GROUP_CONCAT(DISTINCT tf.filename) as filenames,
178
+ GROUP_CONCAT(DISTINCT tf.file_path) as file_paths
179
+ FROM tables t
180
+ LEFT JOIN table_files tf ON t.table_id = tf.table_id
181
+ WHERE t.user_id = ?
182
+ GROUP BY t.id, t.user_id, t.table_id, t.table_name, t.created_time
183
+ ''', (user_id,)).fetchall()
184
+
185
+ result = []
186
+ for table in tables:
187
+ table_dict = dict(table)
188
+ filenames = table_dict.pop('filenames', '').split(',') if table_dict.get('filenames') else []
189
+ filepaths = table_dict.pop('file_paths', '').split(',') if table_dict.get('file_paths') else []
190
+ table_dict['files'] = [{'filename': f, 'file_path': p} for f, p in zip(filenames, filepaths)]
191
+ result.append(table_dict)
192
+
193
+ return result
 
 
194
 
195
 
196
  @router.delete("/delete_table/{table_id}")