THEZYZSTUDIO commited on
Commit
d2bcd1f
·
verified ·
1 Parent(s): 5cd9b5e

Create search_engine.py

Browse files
Files changed (1) hide show
  1. search_engine.py +14 -0
search_engine.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # [سيرفر النموذج] search_engine.py
2
+ from duckduckgo_search import DDGS
3
+ import json
4
+
5
+ def search_web(query: str, max_results: int = 5) -> str:
6
+ try:
7
+ with DDGS() as ddgs:
8
+ results = list(ddgs.text(query, max_results=max_results))
9
+ if not results:
10
+ return "لا توجد نتائج بحث."
11
+ formatted = "\n".join([f"- {r['title']}: {r['href']}\n {r['body']}" for r in results])
12
+ return f"🔍 نتائج البحث لـ '{query}':\n{formatted}"
13
+ except Exception as e:
14
+ return f"خطأ في البحث: {str(e)}"