เชื่อมต่อเครื่องมือ เปิดใช้งาน Agentic RAG
ตอนนี้มีเครื่องมือที่กำหนดเองพร้อมใช้งานแล้ว ซึ่งสามารถค้นหาคู่มือเครื่องใช้ไฟฟ้าด้วย semantic similarity ได้ ในแบบฝึกหัดนี้ จะนำเครื่องมือดังกล่าวเชื่อมต่อกับ agent เพื่อให้ตอบคำถามจากเนื้อหาในคู่มือได้
เบื้องหลังนั้น มีทรัพยากรที่พร้อมใช้งานอยู่แล้ว ดังนี้
- ตัวแปร
vector_storeที่เก็บเนื้อหาคู่มือที่ค้นหาได้ ApplianceSearchToolสำหรับทำ semantic search- ตัวแปร
modelที่มีโมเดลภาษาที่กำหนดค่าไว้ล่วงหน้าสำหรับ agent
เป้าหมายคือการเชื่อมต่อทุกส่วนเข้าด้วยกัน เพื่อให้ agent ใช้เครื่องมือของคุณตอบคำถามได้เหมือนผู้ช่วยด้านเครื่องใช้ไฟฟ้า
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
AI Agents ด้วย Hugging Face smolagents
คำแนะนำการฝึกหัด
- สร้าง instance ของ
ApplianceSearchToolโดยส่งvector_storeเข้าไปเป็น argument - เพิ่ม
appliance_toolลงใน tools list เมื่อ initializeCodeAgent
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Create appliance search tool
appliance_tool = ApplianceSearchTool(____)
# Create AI assistant for appliance help
assistant = CodeAgent(
tools=[____],
model=model,
instructions="Help with appliance questions using manual information. Search multiple times if needed for complete answers.",
verbosity_level=1,
max_steps=6
)
result = assistant.run("If the AC isn’t cooling and shows error E1, what should I check and what’s the next step?")
print(result)