当前位置:   article > 正文

LangChain_Tools_langchain 网页制作tools

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
)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
# 输入是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
)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号