diff options
| author | tanaka takashi <isazaka@gmail.com> | 2026-08-16 21:34:13 +0900 |
|---|---|---|
| committer | tanaka takashi <isazaka@gmail.com> | 2026-08-16 21:34:13 +0900 |
| commit | a9f083785a7e961a291e5366013fc89c0b801b01 (patch) | |
| tree | cb456d3ee40b00b8b475429a6e29f05c93e0efad /src/ollama_web/tools/search.py | |
| parent | e45e2dbf160445891ec765ffb3e0e14f106cfb56 (diff) | |
refactor: streamline chat flow and improve diagnostics
Store server.log inside OLLAMA_WEB_DATA_DIR and manage the ollama-web file handler through the Starlette lifespan. Close and detach the handler on shutdown to prevent duplicate records and Windows file locks when applications are recreated.
Stop converting DuckDuckGo provider failures into empty search results. Record a query-safe traceback, re-raise the original exception, and let ToolRegistry expose the exception type and message as a tool error without adding or spoofing Referer headers.
Remove the unused non-streaming chat_with_tools implementation and its private helpers. Move capability, options, standard tool, MCP tool, and final tools=[] regression coverage onto the production streaming path.
Add integration coverage for data/server.log placement, handler cleanup, repeated lifespans, and provider 403 diagnostics. Update the Unreleased changelog entry.
Validated with 118 tests, Ruff, mypy, diff checks, real DuckDuckGo searches, successful result-page fetches, and observable 401/403 responses from sites that reject automated retrieval.
Diffstat (limited to 'src/ollama_web/tools/search.py')
| -rw-r--r-- | src/ollama_web/tools/search.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/ollama_web/tools/search.py b/src/ollama_web/tools/search.py index 761f182..773f7f3 100644 --- a/src/ollama_web/tools/search.py +++ b/src/ollama_web/tools/search.py @@ -2,10 +2,14 @@ from __future__ import annotations +import logging + from ddgs import DDGS from ..config import settings +logger = logging.getLogger(__name__) + def web_search(query: str, max_results: int | None = None) -> list[dict[str, str]]: """Search the web using DuckDuckGo and return compact result summaries. @@ -16,7 +20,8 @@ def web_search(query: str, max_results: int | None = None) -> list[dict[str, str Returns: A list of dictionaries with keys 'title', 'href' and 'body' for each - result. Returns an empty list if the search fails or no results are found. + result. Returns an empty list if no results are found. Provider failures + are logged and propagated to the tool execution layer. """ if not query or not query.strip(): return [] @@ -37,7 +42,9 @@ def web_search(query: str, max_results: int | None = None) -> list[dict[str, str } ) except Exception: # noqa: BLE001 - # Swallow network/runtime errors so the chat loop can continue. - return [] + # Preserve the provider exception for the tool layer while recording + # the traceback without logging the potentially sensitive query. + logger.exception("DuckDuckGo web search failed") + raise return results[:limit] |
