文章目录
- 1 使用自定义方式
-
- 1.1 自定义乘法工具
- 1.2 聊天模型
- 1.3 绑定工具的聊天模型
- 1.4 添加模型节点
- 1.5 添加工具节点
- 1.6 添加条件边
- 1.7 编译应用
- 2 使用内置节点方式
-
- 2.1 预定义函数
-
- 2.1.1 函数tools_condition
- 2.1.2 函数add_conditional_edges条件边
- 2.1.3 函数add_edge定向边
- 2.1.4 函数ToolNode工具节点
- 2.2 构建图
- 2.3 编译应用
- 3 定义多个工具
-
- 3.1 自定义加法和乘法工具
- 3.2 绑定工具的聊天模型
- 3.3 构建图
- 3.4 编译应用
- 4 参考附录
1 使用自定义方式
1.1 自定义乘法工具
from langchain_core.tools import tool
@tool
def multiply(first_number: int, second_number: int):
"""Multiplies two numbers together."""
return first_number * second_number

1.2 聊天模型
from langchain_ollama