Spaces:
Sleeping
Sleeping
Update sherlock2.py
Browse files- 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 |
-
#
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
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 |
|