Skip to content

Commit 6da39dc

Browse files
committed
duckduckgo is updated to use the new package
1 parent cdd5ea7 commit 6da39dc

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

camel/toolkits/search_toolkit.py

Lines changed: 5 additions & 7 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,16 +192,14 @@ 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:
202-
results = ddgs.text(
203-
keywords=query, max_results=number_of_result_pages
204-
)
202+
results = ddgs.text(query, max_results=number_of_result_pages)
205203
# Iterate over results found
206204
for i, result in enumerate(results, start=1):
207205
# Creating a response object with a similar structure
@@ -219,7 +217,7 @@ def search_duckduckgo(
219217
elif source == "images":
220218
try:
221219
results = ddgs.images(
222-
keywords=query, max_results=number_of_result_pages
220+
query, max_results=number_of_result_pages
223221
)
224222
# Iterate over results found
225223
for i, result in enumerate(results, start=1):
@@ -239,7 +237,7 @@ def search_duckduckgo(
239237
elif source == "videos":
240238
try:
241239
results = ddgs.videos(
242-
keywords=query, max_results=number_of_result_pages
240+
query, max_results=number_of_result_pages
243241
)
244242
# Iterate over results found
245243
for i, result in enumerate(results, start=1):

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ rag = [
8787
"chromadb>=0.6.0,<1.0.0",
8888
]
8989
web_tools = [
90-
"duckduckgo-search>=6.3.5,<7",
90+
"ddgs>=7.0.0,<10",
9191
"wikipedia>=1,<2",
9292
"firecrawl-py>=1.0.0,<2",
9393
"apify_client>=1.8.1,<2",
@@ -245,7 +245,7 @@ owl = [
245245
"tabulate>=0.9.0",
246246
"openpyxl>=3.1.5",
247247
"docx>=0.2.4",
248-
"duckduckgo-search>=6.3.5,<7",
248+
"ddgs>=7.0.0,<10",
249249
"wikipedia>=1,<2",
250250
"playwright>=1.50.0",
251251
"html2text>=2024.2.26",
@@ -317,7 +317,7 @@ all = [
317317
"unstructured==0.16.20; python_version < '3.13'",
318318
"wikipedia>=1,<2",
319319
"linkup-sdk>=0.2.1,<0.3",
320-
"duckduckgo-search>=6.3.5,<7",
320+
"ddgs>=7.0.0,<10",
321321
"wolframalpha>=5.0.0,<6",
322322
"sympy>=1.13.3,<2",
323323
"pyowm>=3.3.0,<4",
@@ -545,7 +545,7 @@ module = [
545545
"huggingface_hub.errors",
546546
"wikipedia",
547547
"linkup-sdk",
548-
"duckduckgo_search",
548+
"ddgs",
549549
"newspaper",
550550
"wolframalpha",
551551
"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)