mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 03:09:49 +08:00
Add a FETCH_PROVIDERS spec table next to SEARCH_PROVIDERS and a deeptutor/services/fetch/providers registry, mirroring the search-provider shape: local (the unchanged in-process extractor, default) and deepseek (POST /v1/tools/fetch, Bearer auth; key from kwargs > env > DeepSeek chat profile). fetch_url_as_markdown gains backend=None -> DEEPTUTOR_FETCH_BACKEND -> local. The scheme/SSRF gate runs before any remote backend so a private URL is never handed to a third party. Retryable backend failures (401/402/403/408/429/5xx, network, missing key) fall back to the local extractor; 400/404/413 and an empty body are hard failures. Remote outcomes keep the requested URL for citations; the crawler/KB site sync stay local. All tests mock HTTP offline.
36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
"""Local fetch backend — the in-process extractor ``web_fetch`` always had."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING, Any
|
|
|
|
from ..base import BaseFetchProvider
|
|
from ..providers import register_fetch_provider
|
|
|
|
if TYPE_CHECKING:
|
|
from deeptutor.tools.web_fetch import FetchOutcome
|
|
|
|
|
|
@register_fetch_provider("local")
|
|
class LocalFetchProvider(BaseFetchProvider):
|
|
"""Registry entry for the default local extraction path.
|
|
|
|
The HTTP + redirect + readability logic stays in
|
|
``deeptutor.tools.web_fetch`` (single source of truth for the SSRF
|
|
gate and the extractor), and ``fetch_url_as_markdown`` dispatches
|
|
straight to it for ``backend="local"`` instead of round-tripping
|
|
through this adapter. The adapter exists so registry consumers treat
|
|
local like any other backend — and so a remote backend's fallback has
|
|
a first-class name.
|
|
"""
|
|
|
|
description = "Fetch and extract readable content locally (default; no third party)."
|
|
|
|
async def fetch(self, url: str, **kwargs: Any) -> FetchOutcome:
|
|
from deeptutor.tools.web_fetch import fetch_url_as_markdown
|
|
|
|
return await fetch_url_as_markdown(url, backend="local", **kwargs)
|
|
|
|
|
|
__all__ = ["LocalFetchProvider"]
|