diff --git a/src/kimi_cli/tools/web/fetch.py b/src/kimi_cli/tools/web/fetch.py index dbe3fe5f5..7c01302a1 100644 --- a/src/kimi_cli/tools/web/fetch.py +++ b/src/kimi_cli/tools/web/fetch.py @@ -2,7 +2,6 @@ from typing import override import aiohttp -import trafilatura from kosong.tooling import CallableTool2, ToolReturnValue from pydantic import BaseModel, Field @@ -14,6 +13,13 @@ from kimi_cli.utils.aiohttp import new_client_session from kimi_cli.utils.logging import logger +try: + import trafilatura + + _has_trafilatura = True +except Exception: + _has_trafilatura = False + class Params(BaseModel): url: str = Field(description="The URL to fetch content from.") @@ -92,6 +98,12 @@ async def fetch_with_http_get(params: Params) -> ToolReturnValue: brief="Empty response body", ) + if not _has_trafilatura: + # trafilatura unavailable (e.g. charset-normalizer binary + # incompatible with current Python), return raw HTML trimmed + builder.write(resp_text[:50000]) + return builder.ok("trafilatura is not available; returning raw page content.") + extracted_text = trafilatura.extract( resp_text, include_comments=True,