ZXAI-Backend / search_tool.py
ZBro7's picture
Update search_tool.py
170c795 verified
raw
history blame contribute delete
887 Bytes
import requests
# 🔥 Your SearXNG endpoint
SEARXNG_URL = "https://funbro-my-search-api.hf.space/search"
def search_web(query, max_results=5):
try:
response = requests.get(
SEARXNG_URL,
params={"q": query, "format": "json"},
timeout=15
)
data = response.json()
results = data.get("results", [])
if not results:
return "No relevant web results found."
compiled = ""
for r in results[:max_results]:
title = r.get("title", "")
content = r.get("content", "")
url = r.get("url", "")
if not title or not content:
continue
compiled += f"""
Title: {title}
Source: {url}
Snippet: {content}
---
"""
return compiled.strip()
except Exception as e:
return f"Search failed: {str(e)}"