refactor: remove duckduckgo-search import error checks
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user