เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

การสร้าง 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.____)
แก้ไขและรันโค้ด