Spaces:
Sleeping
Sleeping
Update sherlock2.py
Browse files- sherlock2.py +9 -7
sherlock2.py
CHANGED
|
@@ -89,13 +89,13 @@ def search_and_scrape_wikipedia(keywords, max_topics_per_query=3, react_model='g
|
|
| 89 |
|
| 90 |
**Thought 1:** I need to search Wikipedia for information related to "{question}".
|
| 91 |
|
| 92 |
-
**Action 1:**
|
| 93 |
|
| 94 |
**Observation 1:** {observation} # This will be filled in during the process
|
| 95 |
|
| 96 |
# ... (Further Thought-Action-Observation steps as needed)
|
| 97 |
|
| 98 |
-
**Action N:**
|
| 99 |
"""
|
| 100 |
|
| 101 |
search_history = set() # Keep track of explored topics to avoid redundancy
|
|
@@ -103,7 +103,8 @@ def search_and_scrape_wikipedia(keywords, max_topics_per_query=3, react_model='g
|
|
| 103 |
react_model = genai.GenerativeModel(react_model) # Initialize the generative model
|
| 104 |
|
| 105 |
for query in keywords:
|
| 106 |
-
|
|
|
|
| 107 |
|
| 108 |
for search_term in search_terms:
|
| 109 |
if search_term in search_history:
|
|
@@ -117,19 +118,20 @@ def search_and_scrape_wikipedia(keywords, max_topics_per_query=3, react_model='g
|
|
| 117 |
|
| 118 |
# Perform ReAct-based search and extraction
|
| 119 |
while True:
|
| 120 |
-
response = react_model.generate_content([react_prompt], stop_sequences=["
|
| 121 |
|
| 122 |
# Extract action and observation from the response
|
| 123 |
-
action, observation = re.findall(r"<(.*?)>(.*?)
|
| 124 |
|
| 125 |
# Update the ReAct prompt with the observation
|
| 126 |
react_prompt = react_prompt.replace("{observation}", observation.strip(), 1) # Replace only the first occurrence
|
| 127 |
|
| 128 |
if action == "finish":
|
| 129 |
answer = observation.strip() # Extract the final answer
|
| 130 |
-
break # Exit the loop when
|
| 131 |
|
| 132 |
-
|
|
|
|
| 133 |
url = page.url
|
| 134 |
|
| 135 |
additional_sources = []
|
|
|
|
| 89 |
|
| 90 |
**Thought 1:** I need to search Wikipedia for information related to "{question}".
|
| 91 |
|
| 92 |
+
**Action 1:**
|
| 93 |
|
| 94 |
**Observation 1:** {observation} # This will be filled in during the process
|
| 95 |
|
| 96 |
# ... (Further Thought-Action-Observation steps as needed)
|
| 97 |
|
| 98 |
+
**Action N:** # The final answer will be extracted from here
|
| 99 |
"""
|
| 100 |
|
| 101 |
search_history = set() # Keep track of explored topics to avoid redundancy
|
|
|
|
| 103 |
react_model = genai.GenerativeModel(react_model) # Initialize the generative model
|
| 104 |
|
| 105 |
for query in keywords:
|
| 106 |
+
# Search Wikipedia (modified line)
|
| 107 |
+
search_terms = wikipedia.search(query, results=max_topics_per_query, suggestion=False, srsearch=query)
|
| 108 |
|
| 109 |
for search_term in search_terms:
|
| 110 |
if search_term in search_history:
|
|
|
|
| 118 |
|
| 119 |
# Perform ReAct-based search and extraction
|
| 120 |
while True:
|
| 121 |
+
response = react_model.generate_content([react_prompt], stop_sequences=[""])
|
| 122 |
|
| 123 |
# Extract action and observation from the response
|
| 124 |
+
action, observation = re.findall(r"<(.*?)>(.*?)", response.text)[-1] # Get the last action and observation
|
| 125 |
|
| 126 |
# Update the ReAct prompt with the observation
|
| 127 |
react_prompt = react_prompt.replace("{observation}", observation.strip(), 1) # Replace only the first occurrence
|
| 128 |
|
| 129 |
if action == "finish":
|
| 130 |
answer = observation.strip() # Extract the final answer
|
| 131 |
+
break # Exit the loop when is encountered
|
| 132 |
|
| 133 |
+
# Get Wikipedia page and URL (modified line)
|
| 134 |
+
page = wikipedia.page(search_term, auto_suggest=False)
|
| 135 |
url = page.url
|
| 136 |
|
| 137 |
additional_sources = []
|