Skip to content

Commit

Permalink
pass args 'proxy' for DDGS (#212)
Browse files Browse the repository at this point in the history
* pass args 'proxy' for DDGS

* proxy for bingsearch
  • Loading branch information
liujiangning30 authored Jul 29, 2024
1 parent 98a94c8 commit ef242e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
12 changes: 9 additions & 3 deletions lagent/actions/bing_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@ def __init__(self,
'researchgate.net',
],
**kwargs):
self.proxy = kwargs.get('proxy')
self.timeout = kwargs.get('timeout', 10)
super().__init__(topk, black_list)

@cached(cache=TTLCache(maxsize=100, ttl=600))
def search(self, query: str, max_retry: int = 3) -> dict:
for attempt in range(max_retry):
try:
response = self._call_ddgs(query, timeout=20)
response = self._call_ddgs(
query, timeout=self.timeout, proxy=self.proxy)
return self._parse_response(response)
except Exception as e:
logging.exception(str(e))
Expand Down Expand Up @@ -91,9 +94,11 @@ def __init__(self,
'youtube.com',
'bilibili.com',
'researchgate.net',
]):
],
**kwargs):
self.api_key = api_key
self.market = region
self.proxy = kwargs.get('proxy')
super().__init__(topk, black_list)

@cached(cache=TTLCache(maxsize=100, ttl=600))
Expand All @@ -114,7 +119,8 @@ def _call_bing_api(self, query: str) -> dict:
endpoint = 'https://api.bing.microsoft.com/v7.0/search'
params = {'q': query, 'mkt': self.market, 'count': f'{self.topk * 2}'}
headers = {'Ocp-Apim-Subscription-Key': self.api_key}
response = requests.get(endpoint, headers=headers, params=params)
response = requests.get(
endpoint, headers=headers, params=params, proxies=self.proxy)
response.raise_for_status()
return response.json()

Expand Down
1 change: 0 additions & 1 deletion lagent/agents/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from .autogpt import * # noqa: F401, F403
from .base_agent import * # noqa: F401, F403
from .internlm2_agent import * # noqa: F401, F403
from .mindsearch_agent import * # noqa: F401, F403
from .react import * # noqa: F401, F403
from .rewoo import * # noqa: F401, F403

0 comments on commit ef242e8

Please sign in to comment.