File size: 1,526 Bytes
f3aacc6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# agent.py - Code de l'agent Cheikh Muhammad
import requests

class CheikhMuhammadAgent:
    def __init__(self):
        self.memories = {}

    def get_weather(self, city="Nouakchott"):
        try:
            geo_url = f"https://geocoding-api.open-meteo.com/v1/search?name={city}&count=1"
            geo_resp = requests.get(geo_url, timeout=10)
            geo_data = geo_resp.json()
            if not geo_data.get("results"):
                return f"ู…ุง ู„ู‚ูŠุชุด ู…ุฏูŠู†ุฉ {city}"
            lat = geo_data["results"][0]["latitude"]
            lon = geo_data["results"][0]["longitude"]
            weather_url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&current_weather=true"
            weather_resp = requests.get(weather_url, timeout=10)
            temp = weather_resp.json()["current_weather"]["temperature"]
            return f"ุงู„ุฌูˆ ููŠ {city}: {temp}ยฐC"
        except Exception:
            return "ุนุฐุฑุงู‹ุŒ ู…ุง ู‚ุฏุฑุชุด ุฃุฌูŠุจ ุงู„ู…ุนู„ูˆู…ุฉ"

    def invoke(self, user_input):
        if "ุทู‚ุณ" in user_input:
            return f"ุจุณู… ุงู„ู„ู‡. {self.get_weather()}"
        elif "ุงู„ุณู„ุงู…" in user_input:
            return "ูˆุนู„ูŠูƒู… ุงู„ุณู„ุงู… ูˆุฑุญู…ุฉ ุงู„ู„ู‡. ูƒูŠู ูŠู…ูƒู†ู†ูŠ ู…ุณุงุนุฏุชูƒุŸ"
        else:
            return "ุงู„ุญู…ุฏ ู„ู„ู‡. ูˆุงู„ู„ู‡ ุฃุนู„ู…."

if __name__ == "__main__":
    agent = CheikhMuhammadAgent()
    print(agent.invoke("ุงู„ุณู„ุงู… ุนู„ูŠูƒู…"))
    print(agent.invoke("ุดู†ูˆ ุงู„ุทู‚ุณุŸ"))