jayash391 commited on
Commit
5aad793
·
verified ·
1 Parent(s): b2b9111

Update sherlock2.py

Browse files
Files changed (1) hide show
  1. sherlock2.py +16 -14
sherlock2.py CHANGED
@@ -164,6 +164,7 @@ def search_and_scrape_wikipedia(keywords, max_topics_per_query=3, react_model='g
164
 
165
  search_history = set()
166
  wikipedia_info = []
 
167
  for query in keywords:
168
  # Use ReAct to search and extract information
169
  react_agent(query)
@@ -174,20 +175,21 @@ def search_and_scrape_wikipedia(keywords, max_topics_per_query=3, react_model='g
174
  for line in response_text.strip().split('\n'):
175
  if line.startswith("Observation"):
176
  observations.append(line.split(':')[-1].strip())
177
-
178
- # Assuming the last observation is the final answer/summary
179
- summary = observations[-1]
180
-
181
- # Get URL from search history (assuming successful search)
182
- url = react_agent._search_urls[-1]
183
-
184
- # Create a dictionary with the extracted information
185
- wikipedia_info.append({
186
- "topic": query, # Using the original query as the topic
187
- "summary": summary,
188
- "url": url
189
- # "additional_sources": # Add this if you implement additional source extraction
190
- })
 
191
 
192
  return wikipedia_info
193
 
 
164
 
165
  search_history = set()
166
  wikipedia_info = []
167
+
168
  for query in keywords:
169
  # Use ReAct to search and extract information
170
  react_agent(query)
 
175
  for line in response_text.strip().split('\n'):
176
  if line.startswith("Observation"):
177
  observations.append(line.split(':')[-1].strip())
178
+
179
+ # Check if observations list is not empty before accessing elements
180
+ if observations:
181
+ summary = observations[-1]
182
+ url = react_agent._search_urls[-1]
183
+
184
+ # Create a dictionary with the extracted information
185
+ wikipedia_info.append({
186
+ "topic": query, # Using the original query as the topic
187
+ "summary": summary,
188
+ "url": url
189
+ })
190
+ else:
191
+ # Handle the case where no observations were found (optional)
192
+ print(f"No observations found for query: {query}")
193
 
194
  return wikipedia_info
195