ABMZD commited on
Commit
f3aacc6
ยท
verified ยท
1 Parent(s): 907464f

Upload agent.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. agent.py +35 -0
agent.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # agent.py - Code de l'agent Cheikh Muhammad
2
+ import requests
3
+
4
+ class CheikhMuhammadAgent:
5
+ def __init__(self):
6
+ self.memories = {}
7
+
8
+ def get_weather(self, city="Nouakchott"):
9
+ try:
10
+ geo_url = f"https://geocoding-api.open-meteo.com/v1/search?name={city}&count=1"
11
+ geo_resp = requests.get(geo_url, timeout=10)
12
+ geo_data = geo_resp.json()
13
+ if not geo_data.get("results"):
14
+ return f"ู…ุง ู„ู‚ูŠุชุด ู…ุฏูŠู†ุฉ {city}"
15
+ lat = geo_data["results"][0]["latitude"]
16
+ lon = geo_data["results"][0]["longitude"]
17
+ weather_url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&current_weather=true"
18
+ weather_resp = requests.get(weather_url, timeout=10)
19
+ temp = weather_resp.json()["current_weather"]["temperature"]
20
+ return f"ุงู„ุฌูˆ ููŠ {city}: {temp}ยฐC"
21
+ except Exception:
22
+ return "ุนุฐุฑุงู‹ุŒ ู…ุง ู‚ุฏุฑุชุด ุฃุฌูŠุจ ุงู„ู…ุนู„ูˆู…ุฉ"
23
+
24
+ def invoke(self, user_input):
25
+ if "ุทู‚ุณ" in user_input:
26
+ return f"ุจุณู… ุงู„ู„ู‡. {self.get_weather()}"
27
+ elif "ุงู„ุณู„ุงู…" in user_input:
28
+ return "ูˆุนู„ูŠูƒู… ุงู„ุณู„ุงู… ูˆุฑุญู…ุฉ ุงู„ู„ู‡. ูƒูŠู ูŠู…ูƒู†ู†ูŠ ู…ุณุงุนุฏุชูƒุŸ"
29
+ else:
30
+ return "ุงู„ุญู…ุฏ ู„ู„ู‡. ูˆุงู„ู„ู‡ ุฃุนู„ู…."
31
+
32
+ if __name__ == "__main__":
33
+ agent = CheikhMuhammadAgent()
34
+ print(agent.invoke("ุงู„ุณู„ุงู… ุนู„ูŠูƒู…"))
35
+ print(agent.invoke("ุดู†ูˆ ุงู„ุทู‚ุณุŸ"))