| from duckduckgo_search import DDGS | |
| def search_web(query: str, max_results: int = 5) -> str: | |
| try: | |
| with DDGS() as ddgs: | |
| results = list(ddgs.text(query, max_results=max_results)) | |
| if not results: | |
| return "لا توجد نتائج بحث." | |
| formatted = "\n".join([f"- {r['title']}: {r['href']}\n {r['body']}" for r in results]) | |
| return f"🔍 نتائج البحث لـ '{query}':\n{formatted}" | |
| except Exception as e: | |
| return f"خطأ في البحث: {str(e)}" |