Spaces:
Sleeping
Sleeping
Update tools.py
Browse files
tools.py
CHANGED
@@ -9,7 +9,7 @@ from state import AgentState
|
|
9 |
from langchain.schema import HumanMessage
|
10 |
import regex as re
|
11 |
import time
|
12 |
-
from duckduckgo_search import
|
13 |
|
14 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
15 |
|
@@ -51,13 +51,13 @@ def web_search_tool(state: AgentState) -> AgentState:
|
|
51 |
if not query:
|
52 |
return {} # nothing to do
|
53 |
|
54 |
-
|
55 |
max_retries = 5
|
56 |
result_text = ""
|
57 |
|
58 |
for attempt in range(1, max_retries + 1):
|
59 |
try:
|
60 |
-
result_text = str(
|
61 |
except Exception as e:
|
62 |
# Network error or timeout—retry up to max_retries
|
63 |
if attempt < max_retries:
|
|
|
9 |
from langchain.schema import HumanMessage
|
10 |
import regex as re
|
11 |
import time
|
12 |
+
from duckduckgo_search import DDGS
|
13 |
|
14 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
15 |
|
|
|
51 |
if not query:
|
52 |
return {} # nothing to do
|
53 |
|
54 |
+
ddg = DDGS()
|
55 |
max_retries = 5
|
56 |
result_text = ""
|
57 |
|
58 |
for attempt in range(1, max_retries + 1):
|
59 |
try:
|
60 |
+
result_text = str(ddg.text(query, max_results=5))
|
61 |
except Exception as e:
|
62 |
# Network error or timeout—retry up to max_retries
|
63 |
if attempt < max_retries:
|