@@ -13,6 +13,8 @@ def browser_base_fetch(api_key: str, project_id: str, link: List[str], text_cont
13
13
- `api_key`: The API key provided by BrowserBase.
14
14
- `project_id`: The ID of the project on BrowserBase where you want to fetch data from.
15
15
- `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).
16
18
17
19
It initializes a Browserbase object with the given API key and project ID,
18
20
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
35
37
api_key (str): The API key provided by BrowserBase.
36
38
project_id (str): The ID of the project on BrowserBase where you want to fetch data from.
37
39
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.
38
42
39
43
Returns:
40
44
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
49
53
browserbase = Browserbase (api_key = api_key , project_id = project_id )
50
54
51
55
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
+
54
70
55
71
return result
0 commit comments