feat: 如何将checkpointer以及session传递给工具来使用呢
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
from typing import Union, Annotated
|
from typing import Union, Annotated, TypedDict
|
||||||
|
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from langchain_core.messages import HumanMessage, AIMessage, ToolMessage
|
from langchain_core.messages import AIMessage, ToolMessage
|
||||||
|
from langchain_core.runnables import RunnableConfig
|
||||||
from langchain_core.tools import tool
|
from langchain_core.tools import tool
|
||||||
from langgraph.graph.state import CompiledStateGraph
|
from langgraph.graph.state import CompiledStateGraph
|
||||||
from langgraph.prebuilt import create_react_agent
|
from langgraph.prebuilt import create_react_agent
|
||||||
@@ -58,44 +59,28 @@ def tool_add(
|
|||||||
return float(number1) + float(number2)
|
return float(number1) + float(number2)
|
||||||
|
|
||||||
|
|
||||||
|
class BookHotelData(TypedDict):
|
||||||
|
hotel_id: str
|
||||||
|
proj_id: str
|
||||||
|
user_id: str
|
||||||
|
|
||||||
|
|
||||||
@tool(name_or_callable="tool_book_hotel", description="一个用于预定酒店的工具")
|
@tool(name_or_callable="tool_book_hotel", description="一个用于预定酒店的工具")
|
||||||
def tool_book_hotel() -> str:
|
def tool_book_hotel(config: RunnableConfig) -> str:
|
||||||
resume_data = interrupt({
|
book_hotel_data: Union[BookHotelData, str] = interrupt({"title": "请输入酒店预定信息", "formCode": "bookHotel"})
|
||||||
"title": "请确认酒店预定信息",
|
if book_hotel_data == "N":
|
||||||
"form": [
|
|
||||||
{
|
|
||||||
"field": "hotel_name",
|
|
||||||
"type": "input",
|
|
||||||
"label": "酒店名称",
|
|
||||||
"required": True,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"field": "room_type",
|
|
||||||
"type": "select",
|
|
||||||
"label": "客房类型",
|
|
||||||
"options": [
|
|
||||||
{"label": "标间", "value": "标间"},
|
|
||||||
{"label": "单间", "value": "单间"},
|
|
||||||
{"label": "双人间", "value": "双人间"},
|
|
||||||
],
|
|
||||||
"required": True,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"field": "check_in_date",
|
|
||||||
"type": "date",
|
|
||||||
"label": "入住时间",
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"formData": {
|
|
||||||
"hotel_name": '',
|
|
||||||
"room_type": '',
|
|
||||||
"check_in_date": '',
|
|
||||||
}
|
|
||||||
})
|
|
||||||
if resume_data == "N":
|
|
||||||
return f"用户选择取消预定酒店"
|
return f"用户选择取消预定酒店"
|
||||||
|
|
||||||
return ToolMessage(content="预定成功", additional_kwargs={"render": {"type": "DataTable"}})
|
hotel_id = book_hotel_data.get('hotel_id')
|
||||||
|
proj_id = book_hotel_data.get('proj_id')
|
||||||
|
user_id = book_hotel_data.get('user_id')
|
||||||
|
|
||||||
|
print("hotel_id", hotel_id)
|
||||||
|
print("proj_id", proj_id)
|
||||||
|
print("user_id", user_id)
|
||||||
|
print("config", config)
|
||||||
|
|
||||||
|
return "预定成功"
|
||||||
|
|
||||||
|
|
||||||
class ChatMessage(BaseModel):
|
class ChatMessage(BaseModel):
|
||||||
|
|||||||
Reference in New Issue
Block a user