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