Update app.py
Browse files
app.py
CHANGED
@@ -116,7 +116,12 @@ Do not include any other text or explanation. Only return the dictionary.
|
|
116 |
"""
|
117 |
|
118 |
try:
|
119 |
-
|
|
|
|
|
|
|
|
|
|
|
120 |
state["needs_more_info"] = analysis.get('needs_search', False)
|
121 |
state["search_query"] = analysis.get('search_query', '')
|
122 |
|
@@ -136,12 +141,19 @@ Do not include any other text or explanation. Only return the dictionary.
|
|
136 |
def _use_search(self, state: AgentState) -> AgentState:
|
137 |
"""Use the search tool."""
|
138 |
try:
|
|
|
|
|
|
|
139 |
# Use the simplified search function
|
140 |
search_results = simple_search(
|
141 |
query=state["search_query"],
|
142 |
max_results=3
|
143 |
)
|
144 |
|
|
|
|
|
|
|
|
|
145 |
state["history"].append({
|
146 |
'step': 'search',
|
147 |
'query': state["search_query"],
|
@@ -150,6 +162,7 @@ Do not include any other text or explanation. Only return the dictionary.
|
|
150 |
state["needs_more_info"] = False
|
151 |
state["current_step"] = 'final_answer'
|
152 |
except Exception as e:
|
|
|
153 |
state["history"].append({
|
154 |
'step': 'search_error',
|
155 |
'error': str(e)
|
@@ -170,7 +183,16 @@ Do not include any other text or explanation. Only return the dictionary.
|
|
170 |
Provide a clear, concise answer that addresses the original question.
|
171 |
"""
|
172 |
|
173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
return state
|
175 |
|
176 |
def __call__(self, question: str) -> str:
|
|
|
116 |
"""
|
117 |
|
118 |
try:
|
119 |
+
llm_response = self._call_llm_api(prompt)
|
120 |
+
print("\n=== Analyze Question LLM Response ===")
|
121 |
+
print(f"Input: {state['question']}")
|
122 |
+
print(f"LLM Response: {llm_response}")
|
123 |
+
|
124 |
+
analysis = ast.literal_eval(llm_response)
|
125 |
state["needs_more_info"] = analysis.get('needs_search', False)
|
126 |
state["search_query"] = analysis.get('search_query', '')
|
127 |
|
|
|
141 |
def _use_search(self, state: AgentState) -> AgentState:
|
142 |
"""Use the search tool."""
|
143 |
try:
|
144 |
+
print("\n=== Search Tool ===")
|
145 |
+
print(f"Search Query: {state['search_query']}")
|
146 |
+
|
147 |
# Use the simplified search function
|
148 |
search_results = simple_search(
|
149 |
query=state["search_query"],
|
150 |
max_results=3
|
151 |
)
|
152 |
|
153 |
+
print("Search Results:")
|
154 |
+
for i, result in enumerate(search_results, 1):
|
155 |
+
print(f"{i}. {result}")
|
156 |
+
|
157 |
state["history"].append({
|
158 |
'step': 'search',
|
159 |
'query': state["search_query"],
|
|
|
162 |
state["needs_more_info"] = False
|
163 |
state["current_step"] = 'final_answer'
|
164 |
except Exception as e:
|
165 |
+
print(f"Search Error: {e}")
|
166 |
state["history"].append({
|
167 |
'step': 'search_error',
|
168 |
'error': str(e)
|
|
|
183 |
Provide a clear, concise answer that addresses the original question.
|
184 |
"""
|
185 |
|
186 |
+
print("\n=== Generate Final Answer ===")
|
187 |
+
print(f"Question: {state['question']}")
|
188 |
+
print("History:")
|
189 |
+
print(history_str)
|
190 |
+
|
191 |
+
llm_response = self._call_llm_api(prompt)
|
192 |
+
print("\nFinal Answer:")
|
193 |
+
print(llm_response)
|
194 |
+
|
195 |
+
state["final_answer"] = llm_response
|
196 |
return state
|
197 |
|
198 |
def __call__(self, question: str) -> str:
|