Spaces:
Sleeping
Sleeping
Arbnor Tefiki
commited on
Commit
·
7ab72dd
1
Parent(s):
40264e9
Add question analyzer
Browse files
agent/utils/question_analyzer.py
CHANGED
@@ -307,3 +307,51 @@ class QuestionAnalyzer:
|
|
307 |
print(f"Error searching metadata for expected answer: {e}")
|
308 |
|
309 |
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
307 |
print(f"Error searching metadata for expected answer: {e}")
|
308 |
|
309 |
return result
|
310 |
+
|
311 |
+
def find_file_by_task_id(self, task_id: str) -> Optional[str]:
|
312 |
+
"""
|
313 |
+
Find a file path by task_id in metadata.
|
314 |
+
|
315 |
+
Args:
|
316 |
+
task_id: The task ID
|
317 |
+
|
318 |
+
Returns:
|
319 |
+
File path if found, None otherwise
|
320 |
+
"""
|
321 |
+
if not task_id:
|
322 |
+
return None
|
323 |
+
|
324 |
+
# Check if we have this task_id in our metadata
|
325 |
+
if task_id in self.metadata:
|
326 |
+
file_name = self.metadata[task_id].get('file_name')
|
327 |
+
if file_name:
|
328 |
+
file_path = os.path.join(self.resource_dir, file_name)
|
329 |
+
if os.path.exists(file_path):
|
330 |
+
print(f"Found file in metadata for task_id {task_id}: {file_path}")
|
331 |
+
return file_path
|
332 |
+
|
333 |
+
# Search through metadata file again to find the task_id
|
334 |
+
try:
|
335 |
+
with open(self.metadata_path, 'r', encoding='utf-8') as f:
|
336 |
+
for line in f:
|
337 |
+
try:
|
338 |
+
entry = json.loads(line.strip())
|
339 |
+
if entry.get('task_id') == task_id and 'file_name' in entry:
|
340 |
+
file_name = entry['file_name']
|
341 |
+
file_path = os.path.join(self.resource_dir, file_name)
|
342 |
+
if os.path.exists(file_path):
|
343 |
+
print(f"Found file in metadata for task_id {task_id}: {file_path}")
|
344 |
+
return file_path
|
345 |
+
|
346 |
+
# If the file doesn't exist with the exact path, look for similar files
|
347 |
+
for existing_file in os.listdir(self.resource_dir):
|
348 |
+
if task_id in existing_file:
|
349 |
+
file_path = os.path.join(self.resource_dir, existing_file)
|
350 |
+
print(f"Found file matching task_id {task_id}: {file_path}")
|
351 |
+
return file_path
|
352 |
+
except json.JSONDecodeError:
|
353 |
+
continue
|
354 |
+
except Exception as e:
|
355 |
+
print(f"Error searching metadata for file by task_id: {e}")
|
356 |
+
|
357 |
+
return None
|