Upload agent.py with huggingface_hub
Browse files
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}¤t_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("ุดูู ุงูุทูุณุ"))
|