@@ -13,6 +13,8 @@ def browser_base_fetch(api_key: str, project_id: str, link: List[str], text_cont
1313 - `api_key`: The API key provided by BrowserBase.
1414 - `project_id`: The ID of the project on BrowserBase where you want to fetch data from.
1515 - `link`: The URL or link that you want to fetch data from.
16+ - `text_content`: A boolean flag to specify whether to return only the text content (True) or the full HTML (False).
17+ - `async_mode`: A boolean flag that determines whether the function runs asynchronously (True) or synchronously (False, default).
1618
1719 It initializes a Browserbase object with the given API key and project ID,
1820 then uses this object to load the specified link.
@@ -35,6 +37,8 @@ def browser_base_fetch(api_key: str, project_id: str, link: List[str], text_cont
3537 api_key (str): The API key provided by BrowserBase.
3638 project_id (str): The ID of the project on BrowserBase where you want to fetch data from.
3739 link (str): The URL or link that you want to fetch data from.
40+ text_content (bool): Whether to return only the text content (True) or the full HTML (False). Defaults to True.
41+ async_mode (bool): Whether to run the function asynchronously (True) or synchronously (False). Defaults to False.
3842
3943 Returns:
4044 object: The result of the loading operation.
@@ -49,7 +53,19 @@ def browser_base_fetch(api_key: str, project_id: str, link: List[str], text_cont
4953 browserbase = Browserbase (api_key = api_key , project_id = project_id )
5054
5155 result = []
52- for l in link :
53- result .append (browserbase .load (l , text_content = text_content ))
56+ async def _async_fetch_link (l ):
57+ return await asyncio .to_thread (browserbase .load , l , text_content = text_content )
58+
59+ if async_mode :
60+ async def _async_browser_base_fetch ():
61+ for l in link :
62+ result .append (await _async_fetch_link (l ))
63+ return result
64+
65+ result = asyncio .run (_async_browser_base_fetch ())
66+ else :
67+ for l in link :
68+ result .append (browserbase .load (l , text_content = text_content ))
69+
5470
5571 return result
0 commit comments