Spaces:
Sleeping
Sleeping
Update rag_routerv2.py
Browse files- 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 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
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}")
|