Introduction aux smolagents de Hugging Face

Agents IA avec Hugging Face smolagents

Adel Nehme

VP of AI Curriculum, DataCamp

Agents IA avec Hugging Face smolagents

Agents IA avec Hugging Face smolagents

Agents IA avec Hugging Face smolagents

Agents IA avec Hugging Face smolagents

Agents IA avec Hugging Face smolagents

Définition d'un agent IA

Agents IA avec Hugging Face smolagents

Des chatbots aux agents

Chatbots :

  • Répondent en langage naturel
  • Passifs et réactifs

Agents :

  • Peuvent agir (recherche web, lecture de fichiers, analyse de données, etc.)
  • Raisonnent activement vers un objectif

Les agents suivent un cycle :

Agents IA avec Hugging Face smolagents

Exemple : Recherche de prix des concurrents

Tout à partir d'une seule invite !

Agents IA avec Hugging Face smolagents

Qu'est-ce que smolagents ?

  • Framework Python léger
  • Développé par Hugging Face

Supporte deux types d'agents :

  • ToolCallingAgent : Utilise des appels de fonctions structurés
  • CodeAgent : Écrit et exécute du code Python
Agents IA avec Hugging Face smolagents

Comment fonctionne l'appel de fonction

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"}
Agents IA avec Hugging Face smolagents

Comment fonctionnent les agents de code

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'])
Agents IA avec Hugging Face smolagents

Le flux des agents de code

La recherche montre un taux de succès ~20% plus élevé que les méthodes d'appel de fonction.

1 https://huggingface.co/papers/2402.01030
Agents IA avec Hugging Face smolagents

Passons à la pratique !

Agents IA avec Hugging Face smolagents

Preparing Video For Download...