LangChain_Tools

1、Tools 可以被Agent、Chain、LLM所使用。

2、tool 的必备属性有:name、description、JSON schema (tool输入)、调用的函数、工具的结果是否应直接返回给用户。其中name、description和 JSON schema 可用于提示 LLM、写入在LLM的system prompt当中,以便它知道如何指定要执行的操作,然后调用的函数相当于执行该操作。

3、tool建议:输入越简单、LLM越容易使用,比如单个字符串。

4、自定义tool实现:Defining Custom Tools
推荐使用 StructuredTool 类构建 tool

# 输入为单个字符串
def search_function(query: str):
    return "LangChain"


search = StructuredTool.from_function(
    func=search_function,
    name="Search",
    description="useful for when you need to answer questions about current events",
    # coroutine= ... <- you can specify an async method if desired as well
)
# 输入是dict
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."""
    return a * b


calculator = StructuredTool.from_function(
    func=multiply,
    name="Calculator",
    description="multiply numbers",
    args_schema=CalculatorInput,
    return_direct=True,
    # coroutine= ... <- you can specify an async method if desired as well
)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值