refactor: remove duckduckgo-search import error checks

This commit is contained in:
Michael
2026-06-30 22:34:18 +02:00
parent 6ed91b05db
commit 5203cf89a0
2 changed files with 12 additions and 50 deletions
+5 -16
View File
@@ -20,6 +20,11 @@ import time
from typing import Any
import httpx
from duckduckgo_search import DDGS # type: ignore[import-untyped]
from duckduckgo_search.exceptions import ( # type: ignore[import-untyped]
DuckDuckGoSearchException,
RatelimitException,
)
from gitea.config import SEARXNG_URL
@@ -311,22 +316,6 @@ class ResearchTools:
logger.info("SearXNG unavailable; falling back to DuckDuckGo")
# --- Tier 2: DDGS library (handles sessions, cookies, rate limits) ---
try:
from duckduckgo_search import DDGS # type: ignore[import-untyped]
except ImportError:
logger.debug("duckduckgo-search not installed; using httpx fallback")
return self._web_search_fallback(query, num_results)
# Import exception types (package versions differ on exact names)
try:
from duckduckgo_search.exceptions import ( # type: ignore[import-untyped]
RatelimitException,
DuckDuckGoSearchException,
)
except ImportError:
RatelimitException = Exception # type: ignore[assignment,misc]
DuckDuckGoSearchException = Exception # type: ignore[assignment,misc]
last_exc: Exception | None = None
for attempt in range(3):
try: