# 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("شنو الطقس؟"))