pvanand commited on
Commit
afd5786
1 Parent(s): e08d293

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +52 -30
main.py CHANGED
@@ -184,42 +184,64 @@ import logging
184
  from typing import Optional
185
 
186
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
  def get_collection_files(collection_id: str, user_id: str) -> str:
188
- """
189
- Synchronously get list of files in the specified collection using the external API
190
- with proper timeout and error handling.
191
- """
192
  try:
193
- url = "https://pvanand-documind-api-v2.hf.space/rag/get_collection_files"
194
- params = {
195
- "collection_id": collection_id,
196
- "user_id": user_id
197
- }
198
- headers = {
199
- 'accept': 'application/json'
200
- }
201
 
202
- logger.debug(f"Requesting collection files for user {user_id}, collection {collection_id}")
 
 
 
203
 
204
- # Set timeout to 5 seconds
205
- response = requests.post(url, params=params, headers=headers, data='', timeout=5)
206
 
207
- if response.status_code == 200:
208
- logger.info(f"Successfully retrieved collection files: {response.text[:100]}...")
209
- return response.text
210
- else:
211
- logger.error(f"API error (status {response.status_code}): {response.text}")
212
- return f"Error fetching files (status {response.status_code})"
213
-
214
- except Timeout:
215
- logger.error("Timeout while fetching collection files")
216
- return "Error: Request timed out"
217
- except RequestException as e:
218
- logger.error(f"Network error fetching collection files: {str(e)}")
219
- return f"Error: Network issue - {str(e)}"
220
  except Exception as e:
221
- logger.error(f"Error fetching collection files: {str(e)}", exc_info=True)
222
- return f"Error fetching files: {str(e)}"
223
 
224
  def format_for_model(state: dict, config: Optional[RunnableConfig] = None) -> list[BaseMessage]:
225
  """
 
184
  from typing import Optional
185
 
186
 
187
+ # def get_collection_files(collection_id: str, user_id: str) -> str:
188
+ # """
189
+ # Synchronously get list of files in the specified collection using the external API
190
+ # with proper timeout and error handling.
191
+ # """
192
+ # try:
193
+ # url = "https://pvanand-documind-api-v2.hf.space/rag/get_collection_files"
194
+ # params = {
195
+ # "collection_id": collection_id,
196
+ # "user_id": user_id
197
+ # }
198
+ # headers = {
199
+ # 'accept': 'application/json'
200
+ # }
201
+
202
+ # logger.debug(f"Requesting collection files for user {user_id}, collection {collection_id}")
203
+
204
+ # # Set timeout to 5 seconds
205
+ # response = requests.post(url, params=params, headers=headers, data='', timeout=5)
206
+
207
+ # if response.status_code == 200:
208
+ # logger.info(f"Successfully retrieved collection files: {response.text[:100]}...")
209
+ # return response.text
210
+ # else:
211
+ # logger.error(f"API error (status {response.status_code}): {response.text}")
212
+ # return f"Error fetching files (status {response.status_code})"
213
+
214
+ # except Timeout:
215
+ # logger.error("Timeout while fetching collection files")
216
+ # return "Error: Request timed out"
217
+ # except RequestException as e:
218
+ # logger.error(f"Network error fetching collection files: {str(e)}")
219
+ # return f"Error: Network issue - {str(e)}"
220
+ # except Exception as e:
221
+ # logger.error(f"Error fetching collection files: {str(e)}", exc_info=True)
222
+ # return f"Error fetching files: {str(e)}"
223
+
224
+
225
  def get_collection_files(collection_id: str, user_id: str) -> str:
226
+ """Get list of files in the specified collection"""
 
 
 
227
  try:
228
+ # Get the full collection name
229
+ collection_name = f"{user_id}_{collection_id}"
 
 
 
 
 
 
230
 
231
+ # Open the table and convert to pandas
232
+ table = db.open_table(collection_name)
233
+ df = table.to_pandas()
234
+ print(df.head())
235
 
 
 
236
 
237
+ # Get unique file names
238
+ unique_files = df['file_name'].unique()
239
+
240
+ # Join the file names into a string
241
+ return ", ".join(unique_files)
 
 
 
 
 
 
 
 
242
  except Exception as e:
243
+ logging.error(f"Error getting collection files: {str(e)}")
244
+ return f"Error getting files: {str(e)}"
245
 
246
  def format_for_model(state: dict, config: Optional[RunnableConfig] = None) -> list[BaseMessage]:
247
  """