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}¤t_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("ุดูู ุงูุทูุณุ"))
|