docs: document anthropic features (#30030)

Update integrations page with extended thinking feature.

Update API reference with extended thinking and citations.
This commit is contained in:
ccurme
2025-02-27 19:37:04 -05:00
committed by GitHub
parent 6c7c8a164f
commit 0dbcc1d099
2 changed files with 140 additions and 0 deletions

View File

@@ -315,6 +315,59 @@
"ai_msg.tool_calls"
]
},
{
"cell_type": "markdown",
"id": "6e36d25c-f358-49e5-aefa-b99fbd3fec6b",
"metadata": {},
"source": [
"## Extended thinking\n",
"\n",
"Claude 3.7 Sonnet supports an [extended thinking](https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking) feature, which will output the step-by-step reasoning process that led to its final answer.\n",
"\n",
"To use it, specify the `thinking` parameter when initializing `ChatAnthropic`. It can also be passed in as a kwarg during invocation.\n",
"\n",
"You will need to specify a token budget to use this feature. See usage example below:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "a34cf93b-8522-43a6-a3f3-8a189ddf54a7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[\n",
" {\n",
" \"signature\": \"ErUBCkYIARgCIkCx7bIPj35jGPHpoVOB2y5hvPF8MN4lVK75CYGftmVNlI4axz2+bBbSexofWsN1O/prwNv8yPXnIXQmwT6zrJsKEgwJzvks0yVRZtaGBScaDOm9xcpOxbuhku1zViIw9WDgil/KZL8DsqWrhVpC6TzM0RQNCcsHcmgmyxbgG9g8PR0eJGLxCcGoEw8zMQu1Kh1hQ1/03hZ2JCOgigpByR9aNPTwwpl64fQUe6WwIw==\",\n",
" \"thinking\": \"To find the cube root of 50.653, I need to find the value of $x$ such that $x^3 = 50.653$.\\n\\nI can try to estimate this first. \\n$3^3 = 27$\\n$4^3 = 64$\\n\\nSo the cube root of 50.653 will be somewhere between 3 and 4, but closer to 4.\\n\\nLet me try to compute this more precisely. I can use the cube root function:\\n\\ncube root of 50.653 = 50.653^(1/3)\\n\\nLet me calculate this:\\n50.653^(1/3) \\u2248 3.6998\\n\\nLet me verify:\\n3.6998^3 \\u2248 50.6533\\n\\nThat's very close to 50.653, so I'm confident that the cube root of 50.653 is approximately 3.6998.\\n\\nActually, let me compute this more precisely:\\n50.653^(1/3) \\u2248 3.69981\\n\\nLet me verify once more:\\n3.69981^3 \\u2248 50.652998\\n\\nThat's extremely close to 50.653, so I'll say that the cube root of 50.653 is approximately 3.69981.\",\n",
" \"type\": \"thinking\"\n",
" },\n",
" {\n",
" \"text\": \"The cube root of 50.653 is approximately 3.6998.\\n\\nTo verify: 3.6998\\u00b3 = 50.6530, which is very close to our original number.\",\n",
" \"type\": \"text\"\n",
" }\n",
"]\n"
]
}
],
"source": [
"import json\n",
"\n",
"from langchain_anthropic import ChatAnthropic\n",
"\n",
"llm = ChatAnthropic(\n",
" model=\"claude-3-7-sonnet-latest\",\n",
" max_tokens=5000,\n",
" thinking={\"type\": \"enabled\", \"budget_tokens\": 2000},\n",
")\n",
"\n",
"response = llm.invoke(\"What is the cube root of 50.653?\")\n",
"print(json.dumps(response.content, indent=2))"
]
},
{
"cell_type": "markdown",
"id": "301d372f-4dec-43e6-b58c-eee25633e1a6",