from langchain_core.tools import tool
@tooldefmultiply(a:int,b:int)->int:"""Multiply two numbers"""return a*b
print(multiply.name)# multiplyprint(multiply.description)# Multiply two numbersprint(multiply.args)# {'a': {'title': 'A', 'type': 'integer'}, 'b': {'title': 'B', 'type': 'integer'}}
2.1.2 工具描述方式1:传参
通过将工具名称和 JSON 参数传递给工具装饰器进行自定义
from langchain_core.tools import tool
from pydantic import BaseModel, Field
classCalculatorInput(BaseModel):
a:int= Field(description="The first number")
b:int= Field(description="The second number")@tool("multiplication-tool", args_schema=CalculatorInput, return_direct=True)defmultiply(a:int, b:int)->int:"""Multiply two numbers"""return a * b
print(multiply.name)# multiplication-toolprint(multiply.description)# Multiply two numbersprint(multiply.args)# {'a': {'title': 'A', 'type': 'integer'}, 'b': {'title': 'B', 'type': 'integer'}}print(multiply.return_direct)# True
2.1.3 工具描述方式2:文档字符串
@tool 可以选择性地解析 Google 风格文档字符串,并将文档字符串组件(如参数描述)与工具模式的相关部分关联起来。
@tool(parse_docstring=True)deffoo(bar:str, baz:int)->str:"""The foo.
Args:
bar: The bar.
baz: The baz.
"""return bar
foo.args_schema.schema()
我需要将 iPhone 下载文件夹中的文件传输到 Windows 11 电脑上。我该怎么做?我可以在 Windows 11 上访问 iPhone 下载吗?
由于 iOS 和 Windows 系统之间的差异,在 PC 上访问 iPhone 文件似乎颇具挑战性。然而,只要使用正确的工具…
第 4 题 字符串分割 (Word Break) 难度: Medium备注:出自 leetcode题目描述 Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For example, given s "l…
自从接触了Amazon Q,我陆陆续续写了不少小软件,其中这个项目是一个典型的例子,自己平时来使用,也分享给一些 NAS 爱好者来用。 故事还要用上次折腾黑群晖说起,本意想把 NAS 和打印机共享二合一的,所以把闲着…