Giới thiệu về Hugging Face smolagents

AI Agents với Hugging Face smolagents

Adel Nehme

VP of AI Curriculum, DataCamp

AI Agents với Hugging Face smolagents

AI Agents với Hugging Face smolagents

AI Agents với Hugging Face smolagents

AI Agents với Hugging Face smolagents

AI Agents với Hugging Face smolagents

Định nghĩa tác nhân AI

AI Agents với Hugging Face smolagents

Từ Chatbot đến Tác nhân

Chatbot:

  • Trả lời bằng ngôn ngữ tự nhiên
  • Thụ động, phản ứng theo yêu cầu

Tác nhân (Agent):

  • Có thể hành động (tìm web, đọc tệp, phân tích dữ liệu, v.v.)
  • Chủ động suy luận để đạt mục tiêu

Chu trình của tác nhân:

AI Agents với Hugging Face smolagents

Ví dụ: Nghiên cứu giá đối thủ

Tất cả chỉ từ một prompt!

AI Agents với Hugging Face smolagents

smolagents là gì?

  • Framework Python nhẹ
  • Phát triển bởi Hugging Face

Hỗ trợ hai loại tác nhân:

  • ToolCallingAgent: Gọi hàm có cấu trúc
  • CodeAgent: Viết và chạy mã Python
AI Agents với Hugging Face smolagents

Cách hoạt động của 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 với Hugging Face smolagents

Cách hoạt động của 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 với Hugging Face smolagents

Luồng hoạt động của Code Agent

Nghiên cứu cho thấy tỷ lệ thành công cao hơn ~20% so với phương pháp function-calling.

1 https://huggingface.co/papers/2402.01030
AI Agents với Hugging Face smolagents

Ayo berlatih!

AI Agents với Hugging Face smolagents

Preparing Video For Download...