community[minor]: Improve Brave Search Tool, allow api key in env var (#30364)

- **Description:** 

- Make Brave Search Tool consistent with other tools and allow reading
its api key from `BRAVE_SEARCH_API_KEY` instead of having to pass the
api key manually (no breaking changes)
- Improve Brave Search Tool by storing api key in `SecretStr` instead of
plain `str`.
    - Add unit test for `BraveSearchWrapper`
    - Reflect the changes in the documentation
  - **Issue:** N/A
  - **Dependencies:** N/A
  - **Twitter handle:** ivan_brko
This commit is contained in:
Ivan Brko
2025-03-31 20:48:52 +02:00
committed by GitHub
parent 0c623045b5
commit ecff055096
5 changed files with 101 additions and 9 deletions

View File

@@ -43,12 +43,21 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"id": "5b14008a",
"metadata": {},
"outputs": [],
"source": [
"tool = BraveSearch.from_api_key(api_key=api_key, search_kwargs={\"count\": 3})"
"tool = BraveSearch.from_api_key(api_key=api_key, search_kwargs={\"count\": 3})\n",
"\n",
"# or if you want to get the api key from environment variable BRAVE_SEARCH_API_KEY, and leave search_kwargs empty\n",
"# tool = BraveSearch()\n",
"\n",
"# or if you want to provide just the api key, and leave search_kwargs empty\n",
"# tool = BraveSearch.from_api_key(api_key=api_key)\n",
"\n",
"# or if you want to provide just the search_kwargs and read the api key from the BRAVE_SEARCH_API_KEY environment variable\n",
"# tool = BraveSearch.from_search_kwargs(search_kwargs={\"count\": 3})"
]
},
{