Skip to content

Commit 95d9d38

Browse files
[fix] update the duckduckgo-search package to ddgs (#3501)
Co-authored-by: Wendong-Fan <[email protected]> Co-authored-by: Wendong-Fan <[email protected]>
1 parent 9699a23 commit 95d9d38

File tree

4 files changed

+129
-32
lines changed

4 files changed

+129
-32
lines changed

camel/toolkits/search_toolkit.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def search_linkup(
165165
except Exception as e:
166166
return {"error": f"An unexpected error occurred: {e!s}"}
167167

168-
@dependencies_required("duckduckgo_search")
168+
@dependencies_required("ddgs")
169169
def search_duckduckgo(
170170
self,
171171
query: str,
@@ -192,15 +192,15 @@ def search_duckduckgo(
192192
List[Dict[str, Any]]: A list of dictionaries where each dictionary
193193
represents a search result.
194194
"""
195-
from duckduckgo_search import DDGS
195+
from ddgs import DDGS
196196

197197
ddgs = DDGS()
198198
responses: List[Dict[str, Any]] = []
199199

200200
if source == "text":
201201
try:
202202
results = ddgs.text(
203-
keywords=query, max_results=number_of_result_pages
203+
query, max_results=number_of_result_pages
204204
)
205205
# Iterate over results found
206206
for i, result in enumerate(results, start=1):
@@ -219,7 +219,7 @@ def search_duckduckgo(
219219
elif source == "images":
220220
try:
221221
results = ddgs.images(
222-
keywords=query, max_results=number_of_result_pages
222+
query, max_results=number_of_result_pages
223223
)
224224
# Iterate over results found
225225
for i, result in enumerate(results, start=1):
@@ -239,7 +239,7 @@ def search_duckduckgo(
239239
elif source == "videos":
240240
try:
241241
results = ddgs.videos(
242-
keywords=query, max_results=number_of_result_pages
242+
query, max_results=number_of_result_pages
243243
)
244244
# Iterate over results found
245245
for i, result in enumerate(results, start=1):

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ rag = [
8686
"chromadb>=0.6.0,<1.0.0",
8787
]
8888
web_tools = [
89-
"duckduckgo-search>=6.3.5,<7",
89+
"ddgs>=9.0.0,<10",
9090
"wikipedia>=1,<2",
9191
"firecrawl-py>=1.0.0,<2",
9292
"apify_client>=1.8.1,<2",
@@ -244,7 +244,7 @@ owl = [
244244
"tabulate>=0.9.0",
245245
"openpyxl>=3.1.5",
246246
"docx>=0.2.4",
247-
"duckduckgo-search>=6.3.5,<7",
247+
"ddgs>=9.0.0,<10",
248248
"wikipedia>=1,<2",
249249
"playwright>=1.50.0",
250250
"html2text>=2024.2.26",
@@ -316,7 +316,7 @@ all = [
316316
"unstructured==0.16.20; python_version < '3.13'",
317317
"wikipedia>=1,<2",
318318
"linkup-sdk>=0.2.1,<0.3",
319-
"duckduckgo-search>=6.3.5,<7",
319+
"ddgs>=9.0.0,<10",
320320
"wolframalpha>=5.0.0,<6",
321321
"sympy>=1.13.3,<2",
322322
"pyowm>=3.3.0,<4",
@@ -544,7 +544,7 @@ module = [
544544
"huggingface_hub.errors",
545545
"wikipedia",
546546
"linkup-sdk",
547-
"duckduckgo_search",
547+
"ddgs",
548548
"newspaper",
549549
"wolframalpha",
550550
"pyowm",

test/toolkits/test_search_functions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ def test_search_google_without_metatags(mock_get, search_toolkit):
373373

374374
def test_search_duckduckgo_text():
375375
# Mock the DDGS class and its text method
376-
with mock.patch("duckduckgo_search.DDGS") as MockDDGS:
376+
with mock.patch("ddgs.DDGS") as MockDDGS:
377377
# Create a mock instance of DDGS
378378
mock_ddgs_instance = MockDDGS.return_value
379379
mock_ddgs_instance.text.return_value = [
@@ -409,13 +409,13 @@ def test_search_duckduckgo_text():
409409
]
410410

411411
mock_ddgs_instance.text.assert_called_once_with(
412-
keywords="test query", max_results=10
412+
"test query", max_results=10
413413
)
414414

415415

416416
def test_search_duckduckgo_images():
417417
# Mock the DDGS class and its images method
418-
with mock.patch("duckduckgo_search.DDGS") as MockDDGS:
418+
with mock.patch("ddgs.DDGS") as MockDDGS:
419419
mock_ddgs_instance = MockDDGS.return_value
420420
mock_ddgs_instance.images.return_value = [
421421
{
@@ -454,7 +454,7 @@ def test_search_duckduckgo_images():
454454
]
455455

456456
mock_ddgs_instance.images.assert_called_once_with(
457-
keywords="test query", max_results=10
457+
"test query", max_results=10
458458
)
459459

460460

0 commit comments

Comments
 (0)