การสร้าง custom tool
เมื่อมีฟังก์ชันสำหรับดึงข้อมูลลูกค้าจาก DataFrame customers แล้ว ขั้นตอนต่อไปคือแปลงฟังก์ชันนี้ให้เป็น tool ที่ใช้งานร่วมกับ LangChain agents ได้
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การพัฒนาแอปพลิเคชัน LLM ด้วย LangChain
คำแนะนำการฝึกหัด
- เพิ่ม decorator
@toolไว้ก่อนนิยามฟังก์ชันเพื่อแปลงให้เป็น LangChain tool - แสดงอาร์กิวเมนต์ของ tool โดยใช้ attribute
.argsบน tool (เช่น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.____)