-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLangTools.py
More file actions
40 lines (31 loc) · 988 Bytes
/
LangTools.py
File metadata and controls
40 lines (31 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from langchain_core.tools import tool
from pydantic import BaseModel, Field
# define tool using decorator
@tool
def multiply(a: int, b: int) -> int:
''' Multiply two numbers '''
return a*b
# Let's inspect some of the attributes associated with the tool.
print(multiply.name)
print(multiply.description)
print(multiply.args)
# async tool
@tool
async def subtraction(a: int, b: int) -> int:
''' Subtracting two numbers '''
return a-b
print(subtraction.name)
print(subtraction.description)
print(subtraction.args)
# We can also define args using BaseModel
class CalculatorInput(BaseModel):
a: int = Field(description="First number given by user")
b: int = Field(description="Second number given by user")
@tool('Addition tool', args_schema=CalculatorInput, return_direct=True)
def addition(a: int, b: int) -> int:
''' Adding two number '''
return a+b
print(addition.name)
print(addition.description)
print(addition.args)
print(addition.return_direct)