docs: add web search to anthropic docs (#31169)

This commit is contained in:
ccurme 2025-05-08 16:20:11 -04:00 committed by GitHub
parent efc52e18e9
commit 9aac8923a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 1060 additions and 1004 deletions

View File

@ -67,7 +67,9 @@
"cell_type": "markdown", "cell_type": "markdown",
"id": "72ee0c4b-9764-423a-9dbf-95129e185210", "id": "72ee0c4b-9764-423a-9dbf-95129e185210",
"metadata": {}, "metadata": {},
"source": "To enable automated tracing of your model calls, set your [LangSmith](https://docs.smith.langchain.com/) API key:" "source": [
"To enable automated tracing of your model calls, set your [LangSmith](https://docs.smith.langchain.com/) API key:"
]
}, },
{ {
"cell_type": "code", "cell_type": "code",
@ -914,6 +916,43 @@
"Anthropic supports a variety of [built-in tools](https://docs.anthropic.com/en/docs/build-with-claude/tool-use/text-editor-tool), which can be bound to the model in the [usual way](/docs/how_to/tool_calling/). Claude will generate tool calls adhering to its internal schema for the tool:" "Anthropic supports a variety of [built-in tools](https://docs.anthropic.com/en/docs/build-with-claude/tool-use/text-editor-tool), which can be bound to the model in the [usual way](/docs/how_to/tool_calling/). Claude will generate tool calls adhering to its internal schema for the tool:"
] ]
}, },
{
"cell_type": "markdown",
"id": "74988918-f740-4cf6-a02c-7ea8f1927740",
"metadata": {},
"source": [
"### Web search\n",
"\n",
"Claude can use a [web search tool](https://docs.anthropic.com/en/docs/build-with-claude/tool-use/web-search-tool) to run searches and ground its responses with citations."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "a83d4c91-9b7c-49ad-86d6-11a8fdc781b6",
"metadata": {},
"outputs": [],
"source": [
"from langchain_anthropic import ChatAnthropic\n",
"\n",
"llm = ChatAnthropic(model=\"claude-3-5-sonnet-latest\")\n",
"\n",
"tool = {\"type\": \"web_search_20250305\", \"name\": \"web_search\", \"max_uses\": 3}\n",
"llm_with_tools = llm.bind_tools([tool])\n",
"\n",
"response = llm_with_tools.invoke(\"How do I update a web app to TypeScript 5.5?\")"
]
},
{
"cell_type": "markdown",
"id": "2fd5d545-a40d-42b1-ad0c-0a79e2536c9b",
"metadata": {},
"source": [
"### Text editor\n",
"\n",
"The text editor tool can be used to view and modify text files. See docs [here](https://docs.anthropic.com/en/docs/build-with-claude/tool-use/text-editor-tool) for details."
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 1,

View File

@ -866,6 +866,23 @@ class ChatAnthropic(BaseChatModel):
See LangChain `docs <https://python.langchain.com/docs/integrations/chat/anthropic/>`_ See LangChain `docs <https://python.langchain.com/docs/integrations/chat/anthropic/>`_
for more detail. for more detail.
Web search:
.. code-block:: python
from langchain_anthropic import ChatAnthropic
llm = ChatAnthropic(model="claude-3-5-sonnet-latest")
tool = {"type": "web_search_20250305", "name": "web_search", "max_uses": 3}
llm_with_tools = llm.bind_tools([tool])
response = llm_with_tools.invoke(
"How do I update a web app to TypeScript 5.5?"
)
Text editor:
.. code-block:: python .. code-block:: python
from langchain_anthropic import ChatAnthropic from langchain_anthropic import ChatAnthropic