เช็กบิลได้เลย! ให้ Agent เข้าถึงข้อมูล
ที่ AgentsCafé ออร์เดอร์เครื่องดื่มทั้งหมดจะถูกบันทึกไว้ในไฟล์ชื่อ orders.csv ซึ่งประกอบด้วยคอลัมน์: table_id, drink_name และ size
แทนที่จะต้องเลื่อนดูไฟล์ทุกครั้งที่ลูกค้าขอเช็กบิล คุณจะสร้างเครื่องมือที่ค้นหาออร์เดอร์ปัจจุบันทั้งหมดของโต๊ะที่ระบุ
หมายเหตุ: tool และ pandas ถูก import ให้แล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
AI Agents ด้วย Hugging Face smolagents
คำแนะนำการฝึกหัด
- ใช้
table_idเป็นพารามิเตอร์ของฟังก์ชัน เพื่อให้ agent รู้ว่าต้องดึงออร์เดอร์ของโต๊ะไหน - อ่านไฟล์
orders.csvซึ่งเก็บข้อมูลออร์เดอร์เครื่องดื่มทั้งหมด - Return รายการออร์เดอร์เครื่องดื่มของโต๊ะนั้น
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Create a tool that receives the table_id as input
@tool
def lookup_orders(____: str) -> list[str]:
"""
Retrieves the current drink orders for a café table.
Args:
table_id (str): The table's identifier (e.g., "T5").
Returns:
list[str]: A list of drink orders, each formatted like "Latte (Large)".
"""
# Read the orders.csv file
df = pd.read_csv('____')
orders = df[df['table_id'] == table_id].apply(lambda row: f"{row['drink_name']} ({row['size']})", axis=1).tolist()
# Return the table orders
return ____