Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import inspect
|
|
| 5 |
import pandas as pd
|
| 6 |
import json
|
| 7 |
from urllib.parse import quote
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
from smolagents import ToolCallingAgent, DuckDuckGoSearchTool, load_tool, tool, FinalAnswerTool, OpenAIServerModel, VisitWebpageTool
|
|
@@ -37,7 +38,17 @@ model = OpenAIServerModel(
|
|
| 37 |
|
| 38 |
@tool
|
| 39 |
def simple_web_search(query: str, num_results: int = 3) -> str:
|
| 40 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
try:
|
| 42 |
url = f"https://html.duckduckgo.com/html/?q={quote(query)}"
|
| 43 |
headers = {
|
|
@@ -46,8 +57,6 @@ def simple_web_search(query: str, num_results: int = 3) -> str:
|
|
| 46 |
response = requests.get(url, headers=headers, timeout=10)
|
| 47 |
response.raise_for_status()
|
| 48 |
|
| 49 |
-
# This is a simplified parser - you may need to adjust based on actual HTML
|
| 50 |
-
from bs4 import BeautifulSoup
|
| 51 |
soup = BeautifulSoup(response.text, 'html.parser')
|
| 52 |
results = []
|
| 53 |
|
|
@@ -66,7 +75,7 @@ def simple_web_search(query: str, num_results: int = 3) -> str:
|
|
| 66 |
except Exception as e:
|
| 67 |
return json.dumps({"error": str(e)})
|
| 68 |
|
| 69 |
-
simple_web_search = simple_web_search()
|
| 70 |
|
| 71 |
class BasicAgent:
|
| 72 |
def __init__(self):
|
|
|
|
| 5 |
import pandas as pd
|
| 6 |
import json
|
| 7 |
from urllib.parse import quote
|
| 8 |
+
from bs4 import BeautifulSoup
|
| 9 |
|
| 10 |
|
| 11 |
from smolagents import ToolCallingAgent, DuckDuckGoSearchTool, load_tool, tool, FinalAnswerTool, OpenAIServerModel, VisitWebpageTool
|
|
|
|
| 38 |
|
| 39 |
@tool
|
| 40 |
def simple_web_search(query: str, num_results: int = 3) -> str:
|
| 41 |
+
"""
|
| 42 |
+
Performs a web search using DuckDuckGo's HTML interface.
|
| 43 |
+
|
| 44 |
+
Args:
|
| 45 |
+
query (str): The search term to look up (e.g., "latest AI news").
|
| 46 |
+
num_results (int): Maximum number of results to return (default: 3).
|
| 47 |
+
|
| 48 |
+
Returns:
|
| 49 |
+
str: JSON string containing search results or error message.
|
| 50 |
+
Format: [{"title": "...", "link": "...", "snippet": "..."}, ...]
|
| 51 |
+
"""
|
| 52 |
try:
|
| 53 |
url = f"https://html.duckduckgo.com/html/?q={quote(query)}"
|
| 54 |
headers = {
|
|
|
|
| 57 |
response = requests.get(url, headers=headers, timeout=10)
|
| 58 |
response.raise_for_status()
|
| 59 |
|
|
|
|
|
|
|
| 60 |
soup = BeautifulSoup(response.text, 'html.parser')
|
| 61 |
results = []
|
| 62 |
|
|
|
|
| 75 |
except Exception as e:
|
| 76 |
return json.dumps({"error": str(e)})
|
| 77 |
|
| 78 |
+
#simple_web_search = simple_web_search()
|
| 79 |
|
| 80 |
class BasicAgent:
|
| 81 |
def __init__(self):
|