Update app.py
Browse files
app.py
CHANGED
|
@@ -171,6 +171,28 @@ def visit_webpage(url: str) -> str:
|
|
| 171 |
return (text[:500], text[500:1000])
|
| 172 |
|
| 173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
def web_search(query: str, num_results: int = 10):
|
| 175 |
"""
|
| 176 |
Search the internet for the query provided
|
|
@@ -705,7 +727,6 @@ class BasicAgent:
|
|
| 705 |
response = self.safe_app.invoke(state)
|
| 706 |
|
| 707 |
agent_answer = response["output"]
|
| 708 |
-
agent_answer = "FunkMonk"
|
| 709 |
else:
|
| 710 |
agent_answer = fixed_answer
|
| 711 |
# agent_answer = self.agent.run(question)
|
|
|
|
| 171 |
return (text[:500], text[500:1000])
|
| 172 |
|
| 173 |
|
| 174 |
+
def visit_webpage(url: str) -> str:
|
| 175 |
+
headers = {
|
| 176 |
+
"User-Agent": "Mozilla/5.0"
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
response = requests.get(url, headers=headers, timeout=10)
|
| 180 |
+
response.raise_for_status()
|
| 181 |
+
|
| 182 |
+
soup = BeautifulSoup(response.text, "html.parser")
|
| 183 |
+
|
| 184 |
+
# Remove scripts/styles
|
| 185 |
+
for tag in soup(["script", "style"]):
|
| 186 |
+
tag.extract()
|
| 187 |
+
|
| 188 |
+
# Extract more elements (not just <p>)
|
| 189 |
+
elements = soup.find_all(["p", "dd"])
|
| 190 |
+
|
| 191 |
+
text = " \n ".join(el.get_text(strip=False) for el in elements)
|
| 192 |
+
|
| 193 |
+
return (text[:1000], )
|
| 194 |
+
|
| 195 |
+
|
| 196 |
def web_search(query: str, num_results: int = 10):
|
| 197 |
"""
|
| 198 |
Search the internet for the query provided
|
|
|
|
| 727 |
response = self.safe_app.invoke(state)
|
| 728 |
|
| 729 |
agent_answer = response["output"]
|
|
|
|
| 730 |
else:
|
| 731 |
agent_answer = fixed_answer
|
| 732 |
# agent_answer = self.agent.run(question)
|