-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify custom tool creation example (#102)
- Loading branch information
1 parent
e5c2266
commit 841535a
Showing
2 changed files
with
12 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,13 @@ | ||
# This is an example showing how to create a simple calculator skill | ||
|
||
from langchain.pydantic_v1 import BaseModel, Field | ||
from langchain.tools import StructuredTool | ||
from typing import Annotated | ||
|
||
from langchain_core.tools import tool | ||
|
||
class CalculatorInput(BaseModel): | ||
a: int = Field(description="first number") | ||
b: int = Field(description="second number") | ||
|
||
|
||
def multiply(a: int, b: int) -> int: | ||
"""Multiply two numbers.""" | ||
@tool | ||
def multiply( | ||
a: Annotated[int, "first number"], b: Annotated[int, "second number"] | ||
) -> int: | ||
"""Multiple two numbers.""" | ||
return a * b | ||
|
||
|
||
calculator = StructuredTool.from_function( | ||
func=multiply, | ||
name="Calculator", | ||
description="Useful for when you need to multiply two numbers.", | ||
args_schema=CalculatorInput, | ||
return_direct=True, | ||
) |