建立自訂工具
你已經有一個從 customers DataFrame 擷取客戶資料的函式,現在要把這個函式轉換成可與 LangChain 代理(agent)相容的工具。
本練習屬於課程
使用 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.____)