docs: align custom_tool document headers (#13252)

On the [Defining Custom
Tools](https://python.langchain.com/docs/modules/agents/tools/custom_tools)
page, there's a 'Subclassing the BaseTool class' paragraph under the
'Completely New Tools - String Input and Output' header. Also there's
another 'Subclassing the BaseTool' paragraph under no header, which I
think may belong to the 'Custom Structured Tools' header.

Another thing is, there's a 'Using the tool decorator' and a 'Using the
decorator' paragraph, I think should belong to 'Completely New Tools -
String Input and Output' and 'Custom Structured Tools' separately.

This PR moves those paragraphs to corresponding headers.
This commit is contained in:
Junlin Zhou 2023-11-14 01:03:56 +08:00 committed by GitHub
parent 700293cae9
commit 4da2faba41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,7 +29,8 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"# Import things that are needed generically\n", "# Import things that are needed generically\n",
"from langchain.chains import LLMMathChain\nfrom langchain.utilities import SerpAPIWrapper\n", "from langchain.chains import LLMMathChain\n",
"from langchain.utilities import SerpAPIWrapper\n",
"from langchain.agents import AgentType, initialize_agent\n", "from langchain.agents import AgentType, initialize_agent\n",
"from langchain.chat_models import ChatOpenAI\n", "from langchain.chat_models import ChatOpenAI\n",
"from langchain.tools import BaseTool, StructuredTool, Tool, tool" "from langchain.tools import BaseTool, StructuredTool, Tool, tool"
@ -230,7 +231,7 @@
"id": "6f12eaf0", "id": "6f12eaf0",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### Subclassing the BaseTool class\n", "### Subclassing the BaseTool\n",
"\n", "\n",
"You can also directly subclass `BaseTool`. This is useful if you want more control over the instance variables or if you want to propagate callbacks to nested chains or other tools." "You can also directly subclass `BaseTool`. This is useful if you want more control over the instance variables or if you want to propagate callbacks to nested chains or other tools."
] ]
@ -367,7 +368,7 @@
"id": "824eaf74", "id": "824eaf74",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Using the `tool` decorator\n", "### Using the decorator\n",
"\n", "\n",
"To make it easier to define custom tools, a `@tool` decorator is provided. This decorator can be used to quickly create a `Tool` from a simple function. The decorator uses the function name as the tool name by default, but this can be overridden by passing a string as the first argument. Additionally, the decorator will use the function's docstring as the tool's description." "To make it easier to define custom tools, a `@tool` decorator is provided. This decorator can be used to quickly create a `Tool` from a simple function. The decorator uses the function name as the tool name by default, but this can be overridden by passing a string as the first argument. Additionally, the decorator will use the function's docstring as the tool's description."
] ]
@ -531,7 +532,7 @@
"id": "fb0a38eb", "id": "fb0a38eb",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Subclassing the BaseTool\n", "### Subclassing the BaseTool\n",
"\n", "\n",
"The BaseTool automatically infers the schema from the `_run` method's signature." "The BaseTool automatically infers the schema from the `_run` method's signature."
] ]
@ -624,7 +625,7 @@
"id": "7d68b0ac", "id": "7d68b0ac",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Using the decorator\n", "### Using the decorator\n",
"\n", "\n",
"The `tool` decorator creates a structured tool automatically if the signature has multiple arguments." "The `tool` decorator creates a structured tool automatically if the signature has multiple arguments."
] ]
@ -774,7 +775,8 @@
"from langchain.agents import initialize_agent, Tool\n", "from langchain.agents import initialize_agent, Tool\n",
"from langchain.agents import AgentType\n", "from langchain.agents import AgentType\n",
"from langchain.llms import OpenAI\n", "from langchain.llms import OpenAI\n",
"from langchain.chains import LLMMathChain\nfrom langchain.utilities import SerpAPIWrapper\n", "from langchain.chains import LLMMathChain\n",
"from langchain.utilities import SerpAPIWrapper\n",
"\n", "\n",
"search = SerpAPIWrapper()\n", "search = SerpAPIWrapper()\n",
"tools = [\n", "tools = [\n",