Skip to content

Commit

Permalink
Passing down ssl verification as it's available in DDGS class (#1604)
Browse files Browse the repository at this point in the history
## Description

**Please include:**

- **Summary of changes**: DDGS provides SSL verification option (with
verification enabled by default). Adding it to the DuckDuckGo tool also.
- **Related issues**: N/A
- **Motivation and context**: Experimenting with the introduction
example, and ran into SSL issues (cough cough enterprise stuff cough
cough)
- **Environment or dependencies**: No changes.
- **Impact on AI/ML components**: (If applicable) N/A
  • Loading branch information
FaresKi authored Jan 3, 2025
1 parent abf7e01 commit 85ea7e2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions phi/tools/duckduckgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(
proxy: Optional[str] = None,
proxies: Optional[Any] = None,
timeout: Optional[int] = 10,
verify_ssl: bool = True,
):
super().__init__(name="duckduckgo")

Expand All @@ -35,6 +36,8 @@ def __init__(
if news:
self.register(self.duckduckgo_news)

self.verify_ssl: bool = verify_ssl

def duckduckgo_search(self, query: str, max_results: int = 5) -> str:
"""Use this function to search DuckDuckGo for a query.
Expand All @@ -46,7 +49,7 @@ def duckduckgo_search(self, query: str, max_results: int = 5) -> str:
The result from DuckDuckGo.
"""
logger.debug(f"Searching DDG for: {query}")
ddgs = DDGS(headers=self.headers, proxy=self.proxy, proxies=self.proxies, timeout=self.timeout)
ddgs = DDGS(headers=self.headers, proxy=self.proxy, proxies=self.proxies, timeout=self.timeout, verify=self.verify_ssl)
if not self.modifier:
return json.dumps(ddgs.text(keywords=query, max_results=(self.fixed_max_results or max_results)), indent=2)
return json.dumps(
Expand All @@ -65,5 +68,7 @@ def duckduckgo_news(self, query: str, max_results: int = 5) -> str:
The latest news from DuckDuckGo.
"""
logger.debug(f"Searching DDG news for: {query}")
ddgs = DDGS(headers=self.headers, proxy=self.proxy, proxies=self.proxies, timeout=self.timeout)
ddgs = DDGS(
headers=self.headers, proxy=self.proxy, proxies=self.proxies, timeout=self.timeout, verify=self.verify_ssl
)
return json.dumps(ddgs.news(keywords=query, max_results=(self.fixed_max_results or max_results)), indent=2)

1 comment on commit 85ea7e2

@Anki0812
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a parameter in duckduckgo to set ca_cert_file, in primp.Client(), used in DDGS. Disabling SSL is not an acceptable workaround.

Please sign in to comment.