Spaces:
Sleeping
Sleeping
Arbnor Tefiki
commited on
Commit
·
a80f03c
1
Parent(s):
7ab72dd
Modify agents.py
Browse files- agent/agent.py +14 -13
agent/agent.py
CHANGED
@@ -69,11 +69,25 @@ class MultiModalAgent:
|
|
69 |
# Handle general questions that don't require file processing
|
70 |
if not analysis.get('file_path'):
|
71 |
logger.info("No file reference found in question, trying to answer directly")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
direct_answer = self._answer_without_file(question)
|
73 |
if direct_answer:
|
74 |
self.answer_cache[cache_key] = direct_answer
|
75 |
return direct_answer
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
# If direct answering failed, try to find a file in the resource directory
|
78 |
logger.info("Direct answering failed, looking for relevant files")
|
79 |
analysis['file_path'] = self._find_most_relevant_file(question)
|
@@ -91,19 +105,6 @@ class MultiModalAgent:
|
|
91 |
logger.error(f"Resource directory does not exist: {self.resource_dir}")
|
92 |
return f"Error: Resource directory not found at {self.resource_dir}. Please check the path."
|
93 |
|
94 |
-
# Check if we already have the expected answer in the analysis
|
95 |
-
if 'expected_answer' in analysis:
|
96 |
-
logger.info(f"Found expected_answer in analysis: {analysis['expected_answer']}")
|
97 |
-
answer = analysis['expected_answer']
|
98 |
-
self.answer_cache[cache_key] = answer
|
99 |
-
return answer
|
100 |
-
|
101 |
-
# Try to answer with reasoning since no file is found
|
102 |
-
reasoning_answer = self._answer_with_reasoning(question, analysis)
|
103 |
-
if reasoning_answer:
|
104 |
-
self.answer_cache[cache_key] = reasoning_answer
|
105 |
-
return reasoning_answer
|
106 |
-
|
107 |
# If reasoning fails, check if we have an answer in metadata
|
108 |
metadata_answer = self._check_metadata_for_answer(task_id)
|
109 |
if metadata_answer:
|
|
|
69 |
# Handle general questions that don't require file processing
|
70 |
if not analysis.get('file_path'):
|
71 |
logger.info("No file reference found in question, trying to answer directly")
|
72 |
+
|
73 |
+
# Check if we already have the expected answer in the analysis
|
74 |
+
if 'expected_answer' in analysis and analysis['expected_answer']:
|
75 |
+
logger.info(f"Found expected_answer in analysis: {analysis['expected_answer']}")
|
76 |
+
answer = analysis['expected_answer']
|
77 |
+
self.answer_cache[cache_key] = answer
|
78 |
+
return answer
|
79 |
+
|
80 |
direct_answer = self._answer_without_file(question)
|
81 |
if direct_answer:
|
82 |
self.answer_cache[cache_key] = direct_answer
|
83 |
return direct_answer
|
84 |
|
85 |
+
# Try to answer with reasoning since no file is found
|
86 |
+
reasoning_answer = self._answer_with_reasoning(question, analysis)
|
87 |
+
if reasoning_answer:
|
88 |
+
self.answer_cache[cache_key] = reasoning_answer
|
89 |
+
return reasoning_answer
|
90 |
+
|
91 |
# If direct answering failed, try to find a file in the resource directory
|
92 |
logger.info("Direct answering failed, looking for relevant files")
|
93 |
analysis['file_path'] = self._find_most_relevant_file(question)
|
|
|
105 |
logger.error(f"Resource directory does not exist: {self.resource_dir}")
|
106 |
return f"Error: Resource directory not found at {self.resource_dir}. Please check the path."
|
107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
# If reasoning fails, check if we have an answer in metadata
|
109 |
metadata_answer = self._check_metadata_for_answer(task_id)
|
110 |
if metadata_answer:
|