开始使用免费开始使用

创建自定义工具

既然您已经有了一个从 customers DataFrame 提取客户数据的函数,现在就把这个函数转换为与 LangChain 代理兼容的工具吧。

本练习是课程的一部分

使用 LangChain 开发 LLM 应用

查看课程

练习说明

  • 在函数定义前添加 @tool 装饰器,将其转换为 LangChain 工具。
  • 使用工具的 .args 属性打印其参数(例如 tool_name.args)。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Convert the retrieve_customer_info function into a tool
____
def retrieve_customer_info(name: str) -> str:
    """Retrieve customer information based on their name."""
    customer_info = customers[customers['name'] == name]
    return customer_info.to_string()
  
# Print the tool's arguments
print(retrieve_customer_info.____)
编辑并运行代码