Introduction to Hugging Face smolagents

AI Agents ด้วย Hugging Face smolagents

Adel Nehme

VP of AI Curriculum, DataCamp

AI Agents ด้วย Hugging Face smolagents

AI Agents ด้วย Hugging Face smolagents

AI Agents ด้วย Hugging Face smolagents

AI Agents ด้วย Hugging Face smolagents

AI Agents ด้วย Hugging Face smolagents

นิยามของ AI agent

AI Agents ด้วย Hugging Face smolagents

จาก Chatbot สู่ Agent

Chatbot:

  • ตอบสนองด้วยภาษาธรรมชาติ
  • รับและตอบสนองแบบ passive

Agent:

  • ดำเนินการได้ (ค้นหาเว็บ, อ่านไฟล์, วิเคราะห์ข้อมูล ฯลฯ)
  • ใช้เหตุผลเชิงรุกเพื่อบรรลุเป้าหมาย

Agent ทำงานเป็นวงจร:

AI Agents ด้วย Hugging Face smolagents

ตัวอย่าง: การวิจัยราคาคู่แข่ง

ทั้งหมดนี้จาก prompt เดียว!

AI Agents ด้วย Hugging Face smolagents

smolagents คืออะไร?

  • เฟรมเวิร์ก Python ที่มีขนาดเล็กเบา
  • พัฒนาโดย Hugging Face

รองรับ agent 2 ประเภท:

  • ToolCallingAgent: ใช้การเรียกฟังก์ชันแบบมีโครงสร้าง
  • CodeAgent: เขียนและรันโค้ด Python
AI Agents ด้วย Hugging Face smolagents

Function Calling ทำงานอย่างไร?

Action 1: {"tool": "search_company", "company": "Competitor A"}
Action 2: {"tool": "get_pricing", "company": "Competitor A", "plan": "Basic"}
Action 3: {"tool": "get_pricing", "company": "Competitor A", "plan": "Pro"}
Action 4: {"tool": "search_company", "company": "Competitor B"}
Action 5: {"tool": "get_pricing", "company": "Competitor B", "plan": "Basic"}
AI Agents ด้วย Hugging Face smolagents

Code Agent ทำงานอย่างไร?

competitors = ["Competitor A", "Competitor B", "Competitor C"]
pricing_data = {}

for company in competitors:
    company_info = search_company(company)
    plans = extract_pricing_plans(company_info)
    pricing_data[company] = plans

most_affordable_option = min(pricing_data, 
                      key=lambda x: pricing_data[x]['basic_plan'])
AI Agents ด้วย Hugging Face smolagents

การทำงานของ Code Agent

งานวิจัยพบว่ามีอัตราความสำเร็จสูงกว่าวิธี function-calling ประมาณ ~20%

1 https://huggingface.co/papers/2402.01030
AI Agents ด้วย Hugging Face smolagents

มาฝึกกันเถอะ!

AI Agents ด้วย Hugging Face smolagents

Preparing Video For Download...