From c97f0ffc3c218fe232cbd23722f449e598ce7937 Mon Sep 17 00:00:00 2001 From: Wei <21039366+Mai0313@users.noreply.github.com> Date: Tue, 16 Apr 2024 22:07:50 +0800 Subject: [PATCH] [Feat] browser should support custom base url for bing search (#2321) * feat: browser is now support custom base url * fix: replae the base url position. * Update bing_base_url parameter in SimpleTextBrowser class --- autogen/browser_utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/autogen/browser_utils.py b/autogen/browser_utils.py index c6ccbba38e1..99e51fcd4ca 100644 --- a/autogen/browser_utils.py +++ b/autogen/browser_utils.py @@ -36,6 +36,7 @@ def __init__( start_page: Optional[str] = None, viewport_size: Optional[int] = 1024 * 8, downloads_folder: Optional[Union[str, None]] = None, + bing_base_url: str = "https://api.bing.microsoft.com/v7.0/search", bing_api_key: Optional[Union[str, None]] = None, request_kwargs: Optional[Union[Dict[str, Any], None]] = None, ): @@ -47,6 +48,7 @@ def __init__( self.viewport_current_page = 0 self.viewport_pages: List[Tuple[int, int]] = list() self.set_address(self.start_page) + self.bing_base_url = bing_base_url self.bing_api_key = bing_api_key self.request_kwargs = request_kwargs @@ -145,7 +147,7 @@ def _bing_api_call(self, query: str) -> Dict[str, Dict[str, List[Dict[str, Union request_kwargs["stream"] = False # Make the request - response = requests.get("https://api.bing.microsoft.com/v7.0/search", **request_kwargs) + response = requests.get(self.bing_base_url, **request_kwargs) response.raise_for_status() results = response.json()