pvanand commited on
Commit
b6c9315
·
verified ·
1 Parent(s): 1b031c5

Update rag_routerv2.py

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