File size: 2,523 Bytes
3e8eb78
6aae614
9b5b26a
 
256f653
 
9b5b26a
3e8eb78
256f653
 
 
9b5b26a
256f653
3e8eb78
9b5b26a
256f653
 
8c01ffb
256f653
 
 
8c01ffb
256f653
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ae7a494
256f653
ae7a494
256f653
 
 
 
8c01ffb
 
256f653
3e8eb78
256f653
9b5b26a
8c01ffb
256f653
 
 
 
 
861422e
256f653
 
 
 
 
3e8eb78
 
256f653
 
 
 
 
 
 
 
 
 
8c01ffb
8fe992b
256f653
8c01ffb
 
861422e
8fe992b
 
9b5b26a
256f653
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from smolagents import CodeAgent, HfApiModel, load_tool, tool
from tools.final_answer import FinalAnswerTool
from Gradio_UI import GradioUI

import requests
import yaml


# ----------------------------
# 1️⃣ OUTIL : MÉTÉO À PARIS
# ----------------------------
@tool
def get_weather_paris() -> str:
    """Renvoie la météo actuelle à Paris (température + description)."""
    try:
        url = "https://api.open-meteo.com/v1/forecast?latitude=48.8566&longitude=2.3522&current_weather=true"
        response = requests.get(url).json()

        weather = response["current_weather"]
        temperature = weather["temperature"]
        weather_code = weather["weathercode"]

        descriptions = {
            0: "ciel clair",
            1: "principalement clair",
            2: "partiellement nuageux",
            3: "couvert",
            45: "brouillard",
            48: "brouillard givrant",
            51: "bruine légère",
            53: "bruine",
            55: "bruine forte",
            61: "pluie légère",
            63: "pluie",
            65: "pluie forte",
            71: "neige légère",
            73: "neige",
            75: "neige forte",
        }

        description = descriptions.get(weather_code, "conditions météo inconnues")

        return f"À Paris, il fait {temperature}°C avec un {description}."

    except Exception as e:
        return f"Erreur lors de la récupération de la météo : {str(e)}"


# ---------------------------------------------------
# 2️⃣ OUTIL : GÉNÉRATION D’IMAGE
# ---------------------------------------------------
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)


# ---------------------------------
# 3️⃣ CHARGEMENT DU PROMPT SYSTÈME
# ---------------------------------
with open("prompts.yaml", "r") as stream:
    prompt_templates = yaml.safe_load(stream)


# -------------------------
# 4️⃣ MODÈLE UTILISÉ
# -------------------------
model = HfApiModel(
    model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
    max_tokens=2048,
    temperature=0.5,
)


# -------------------------
# 5️⃣ CRÉATION DE L’AGENT
# -------------------------
final_answer = FinalAnswerTool()

agent = CodeAgent(
    model=model,
    tools=[final_answer, get_weather_paris, image_generation_tool],
    max_steps=6,
    verbosity_level=1,
    prompt_templates=prompt_templates
)


# -------------------------
# 6️⃣ LANCEMENT DE GRADIO
# -------------------------
GradioUI(agent).launch()