mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-17 08:29:28 +00:00
docs: update tool calling how-to to pass functions to bind_tools (#24402)
This commit is contained in:
parent
3adf710f1d
commit
ba74341eee
@ -82,30 +82,24 @@
|
|||||||
"## Passing tools to chat models\n",
|
"## Passing tools to chat models\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Chat models that support tool calling features implement a `.bind_tools` method, which \n",
|
"Chat models that support tool calling features implement a `.bind_tools` method, which \n",
|
||||||
"receives a list of LangChain [tool objects](https://api.python.langchain.com/en/latest/tools/langchain_core.tools.BaseTool.html#langchain_core.tools.BaseTool) \n",
|
"receives a list of functions, Pydantic models, or LangChain [tool objects](https://api.python.langchain.com/en/latest/tools/langchain_core.tools.BaseTool.html#langchain_core.tools.BaseTool) \n",
|
||||||
"and binds them to the chat model in its expected format. Subsequent invocations of the \n",
|
"and binds them to the chat model in its expected format. Subsequent invocations of the \n",
|
||||||
"chat model will include tool schemas in its calls to the LLM.\n",
|
"chat model will include tool schemas in its calls to the LLM.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"For example, we can define the schema for custom tools using the `@tool` decorator \n",
|
"For example, below we implement simple tools for arithmetic:"
|
||||||
"on Python functions:"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 1,
|
"execution_count": 2,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"from langchain_core.tools import tool\n",
|
|
||||||
"\n",
|
|
||||||
"\n",
|
|
||||||
"@tool\n",
|
|
||||||
"def add(a: int, b: int) -> int:\n",
|
"def add(a: int, b: int) -> int:\n",
|
||||||
" \"\"\"Adds a and b.\"\"\"\n",
|
" \"\"\"Adds a and b.\"\"\"\n",
|
||||||
" return a + b\n",
|
" return a + b\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"@tool\n",
|
|
||||||
"def multiply(a: int, b: int) -> int:\n",
|
"def multiply(a: int, b: int) -> int:\n",
|
||||||
" \"\"\"Multiplies a and b.\"\"\"\n",
|
" \"\"\"Multiplies a and b.\"\"\"\n",
|
||||||
" return a * b\n",
|
" return a * b\n",
|
||||||
@ -118,12 +112,14 @@
|
|||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"Or below, we define the schema using [Pydantic](https://docs.pydantic.dev):"
|
"LangChain also implements a `@tool` decorator that allows for further control of the tool schema, such as tool names and argument descriptions. See the how-to guide [here](/docs/how_to/custom_tools/#creating-tools-from-functions) for detail.\n",
|
||||||
|
"\n",
|
||||||
|
"We can also define the schema using [Pydantic](https://docs.pydantic.dev):"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": 1,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
@ -343,7 +339,7 @@
|
|||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.11.9"
|
"version": "3.10.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
"nbformat": 4,
|
||||||
|
Loading…
Reference in New Issue
Block a user