Update app.py
Browse files
app.py
CHANGED
@@ -154,9 +154,18 @@ class BasicAgent:
|
|
154 |
state["current_step"] = "sheet"
|
155 |
return state
|
156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
# Regular text question analysis
|
158 |
prompt = (
|
159 |
-
"Decide if this question needs web search.
|
|
|
|
|
160 |
"{\n 'needs_search': bool,\n 'search_query': str\n}\n\n"
|
161 |
f"Question: {state['question']}"
|
162 |
)
|
@@ -167,7 +176,7 @@ class BasicAgent:
|
|
167 |
state["search_query"] = decision.get("search_query", state["question"])
|
168 |
except Exception as e:
|
169 |
print(f"\nLLM Error in question analysis: {str(e)}")
|
170 |
-
state["needs_search"] =
|
171 |
state["search_query"] = state["question"]
|
172 |
|
173 |
state["current_step"] = "search" if state["needs_search"] else "answer"
|
|
|
154 |
state["current_step"] = "sheet"
|
155 |
return state
|
156 |
|
157 |
+
# Check if question is about the file we just processed
|
158 |
+
if state["history"]:
|
159 |
+
last_step = state["history"][-1]["step"]
|
160 |
+
if last_step in ["video", "image", "sheet"]:
|
161 |
+
state["current_step"] = "answer"
|
162 |
+
return state
|
163 |
+
|
164 |
# Regular text question analysis
|
165 |
prompt = (
|
166 |
+
"Decide if this question needs web search. Only use search for factual questions that require external knowledge. "
|
167 |
+
"For questions about files we just processed or simple reasoning, don't use search. "
|
168 |
+
"Respond with a Python dict:\n"
|
169 |
"{\n 'needs_search': bool,\n 'search_query': str\n}\n\n"
|
170 |
f"Question: {state['question']}"
|
171 |
)
|
|
|
176 |
state["search_query"] = decision.get("search_query", state["question"])
|
177 |
except Exception as e:
|
178 |
print(f"\nLLM Error in question analysis: {str(e)}")
|
179 |
+
state["needs_search"] = False # Default to no search on error
|
180 |
state["search_query"] = state["question"]
|
181 |
|
182 |
state["current_step"] = "search" if state["needs_search"] else "answer"
|