chiekh-agent / agent.py
ABMZD's picture
Upload agent.py with huggingface_hub
f3aacc6 verified
Raw
History Blame Contribute Delete
1.53 kB
# 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}&current_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("ุดู†ูˆ ุงู„ุทู‚ุณุŸ"))