Spaces:
Runtime error
Runtime error
File size: 769 Bytes
9f9394b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #
# SPDX-FileCopyrightText: Hadad <hadad@linuxmail.org>
# SPDX-License-Identifier: Apache-2.0
#
import aiohttp
from config import (
SEARXNG,
FORMAT,
TIMEOUT,
AIOHTTP,
HEADERS,
REMINDERS
)
async def web_search(query):
try:
async with aiohttp.ClientSession(
connector=aiohttp.TCPConnector(**AIOHTTP),
timeout=aiohttp.ClientTimeout(total=TIMEOUT),
headers=HEADERS
) as session:
async with session.get(f"{SEARXNG}?q={query}&format={FORMAT}") as response:
response.raise_for_status()
content = await response.text()
return content + "\n\n\n" + REMINDERS
except Exception as error:
return f"Error during web search: {str(error)}" |