TavilySearchResults(
self,
**kwargs: Any = {},
)Tool that queries the Tavily Search API and gets back json.
Setup:
Install ``langchain-openai`` and ``tavily-python``, and set environment variable ``TAVILY_API_KEY``.
.. code-block:: bash
pip install -U langchain-community tavily-python
export TAVILY_API_KEY="your-api-key"
Instantiate:
.. code-block:: python
from langchain_community.tools import TavilySearchResults
tool = TavilySearchResults(
max_results=5,
include_answer=True,
include_raw_content=True,
include_images=True,
# search_depth="advanced",
# include_domains = []
# exclude_domains = []
)
Invoke directly with args:
.. code-block:: python
tool.invoke({'query': 'who won the last french open'})
.. code-block:: json
{
"url": "https://www.nytimes.com...",
"content": "Novak Djokovic won the last French Open by beating Casper Ruud ..."
}
Invoke with tool call:
.. code-block:: python
tool.invoke({"args": {'query': 'who won the last french open'}, "type": "tool_call", "id": "foo", "name": "tavily"})
.. code-block:: python
ToolMessage(
content='{ "url": "https://www.nytimes.com...", "content": "Novak Djokovic won the last French Open by beating Casper Ruud ..." }',
artifact={
'query': 'who won the last french open',
'follow_up_questions': None,
'answer': 'Novak ...',
'images': [
'https://www.amny.com/wp-content/uploads/2023/06/AP23162622181176-1200x800.jpg',
...
],
'results': [
{
'title': 'Djokovic ...',
'url': 'https://www.nytimes.com...',
'content': "Novak...",
'score': 0.99505633,
'raw_content': 'Tennis
Novak ...' }, ... ], 'response_time': 2.92 }, tool_call_id='1', name='tavily_search_results_json', )
The tool response format.
Max search results to return, default is 5
The depth of the search. It can be "basic" or "advanced"
.. versionadded:: 0.2.5
A list of domains to specifically include in the search results.
Default is None, which includes all domains.
.. versionadded:: 0.2.5
A list of domains to specifically exclude from the search results.
Default is None, which doesn't exclude any domains.
.. versionadded:: 0.2.5
Include a short answer to original query in the search results.
Default is False.
.. versionadded:: 0.2.5
Include cleaned and parsed HTML of each site search results.
Default is False.
.. versionadded:: 0.2.5
Include a list of query related images in the response.
Default is False.
.. versionadded:: 0.2.5