From 1c407c28ecf9cf4d979d27eadd6e84c2c624b195 Mon Sep 17 00:00:00 2001 From: spektr Date: Fri, 20 Nov 2026 20:07:32 +0100 Subject: [PATCH] GNAI-023 M8-T4 Fix: SearXNG-Shim liefert href statt nur url (v3.8 liest url.get('href')) Root Cause fuer 'Scraped 0 pages / No content found': gpt-researcher v3.8 baut die Scrape-Liste in skills/researcher.py ueber url.get('href'); der Shim lieferte nur {url, raw_content} -> None-URLs -> Scraper-Crash ('NoneType' ... endswith) -> 0 Inhalte. v3.8 nutzt raw_content NICHT zum Ueberspringen des Scraperns; der Backend scrapt jede href selbst. Shim liefert jetzt {href, url, raw_content} und filtert weiterhin nur selbst erfolgreich gefetchte Seiten (>100 chars). SCRAPER=bs explizit gepinnt (requests+bs4, kein Browser noetig). Verifiziert im Backend- Container: 8/8 URLs mit Inhalt gescraped. research.yml idempotent (changed=0). Befund in GNAI-023 korrigiert/ergaenzt. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe --- .../ai/GNAI-023-PLAN_GPT-Researcher-IAP.md | 38 +++++++++++-------- .../roles/gpt_researcher/defaults/main.yml | 13 +++++-- .../gpt_researcher/files/searxng_shim.py | 27 ++++++++----- 3 files changed, 49 insertions(+), 29 deletions(-) diff --git a/docs/platform/llm-server/ai/GNAI-023-PLAN_GPT-Researcher-IAP.md b/docs/platform/llm-server/ai/GNAI-023-PLAN_GPT-Researcher-IAP.md index f3baca4..c0f5284 100644 --- a/docs/platform/llm-server/ai/GNAI-023-PLAN_GPT-Researcher-IAP.md +++ b/docs/platform/llm-server/ai/GNAI-023-PLAN_GPT-Researcher-IAP.md @@ -224,22 +224,30 @@ Internet → NPM (CT 103, 443) → auth_request-Subrequest an oauth2-proxy `RETRIEVER=custom` + `RETRIEVER_ENDPOINT=http://gptr-searxng-shim:8099/` gegen einen kleinen Shim-Container (`python:3.13-alpine`, Tag-Pin wegen 404-bei-Digest-Pull, `files/searxng_shim.py`), der `?query=` auf SearXNG - `?q=&format=json` mappt und `[{url, raw_content}]` zurückgibt. Shim läuft + `?q=&format=json` mappt und `[{href, url, raw_content}]` zurückgibt + („href“, weil v3.8 genau dieses Feld liest — siehe Befund unten). Shim läuft ohne publish im LLM-Netz (Alias `gptr-searxng-shim`), ruft SearXNG im Egress-Netz. Verifiziert: Shim-Query aus dem Backend-Container liefert echte Ergebnisse; research.yml idempotent. -- **Befund 19.11. (Scraped 0 pages):** der Scraper im gptr-Image ist kaputt - (`Error processing None: 'NoneType' ... endswith`, `Scraped data size: 0`). - Workaround: der Shim fetches die Ergebnisseiten selbst und liefert - `raw_content` mit vollem Seiten-Text (>100 chars) — dann scrapt - gpt-researcher nicht selbst. `SHIM_MAX_RESULTS=8`, Fetch-Cap 200k/Seite, - Timeout 10 s. Verifiziert: shim count 8 mit Seiteninhalt. - -- **Befund 20.11. (weiterhin 0 Quellen):** Retriever ok (142 results via - shim), aber gpt-researcher scrapt trotzdem und crasht am kaputten Scraper - (`Error processing None ... endswith`, `Scraped data size: 0`). Fix im Shim: - nur erfolgreich gefetchte Seiten (>100 chars raw_content) werden - durchgereicht — dann nutzt gpt-researcher raw_content direkt und scrapt - nicht selbst. `RETRIEVERS` (plural) wird zusätzlich gesetzt (v3.8 liest - `RETRIEVER`, neuere Pfade offenbar plural). +- **Befund 20.11. (weiterhin 0 Quellen — Root Cause gefunden):** Retriever + war ok, aber gpt-researcher v3.8 baut die Scrape-Liste in + `skills/researcher.py::_search_relevant_source_urls` über + `url.get("href")` — liest also das Feld **„href“**, nicht „url“. Der Shim + lieferte nur `{"url", "raw_content"}` → alle Einträge `None` → nach + Dedup in `_get_new_urls` genau **1 URL** („Scraping content from 1 URLs“) + → Scraper-Crash `Error processing None: 'NoneType' ... endswith` + (`scraper.py` `link.endswith(".pdf")`) → „Scraped 0 pages“ → „No content + found“. Der Scraper selbst ist nicht kaputt; v3.8 nutzt `raw_content` + aus dem Retriever **nicht** zum Überspringen des Scrapens (nur v3.6 tat + das) — der Backend scrapt jede `href` selbst. +- **Fix 20.11.:** Shim liefert jetzt `{"href", "url", "raw_content"}` pro + Ergebnis und reicht nur selbst erfolgreich gefetchte Seiten (>100 chars + Text, `SHIM_MAX_RESULTS=8`, Cap 200k/Seite, Timeout 10 s) durch — das + Pre-Fetch filtert tote Links, bevor der gptr-Scraper sie abruft. + Zusätzlich `SCRAPER=bs` explizit gepinnt (v3.8-Default ist „bs“ = + requests+bs4, braucht keinen Browser im Image; Default-Pin schützt vor + künftigen Upstream-Wechseln auf browserbasierte Scraper). `RETRIEVERS` + (plural) bleibt zusätzlich gesetzt. Verifiziert im Backend-Container: + CustomRetriever → 8 Ergebnisse mit `href`, `Scraper(..., "bs")` → + **8/8 Seiten mit Inhalt** (1,9k–8k chars), kein None-Crash. diff --git a/llm-server/llm/ansible/roles/gpt_researcher/defaults/main.yml b/llm-server/llm/ansible/roles/gpt_researcher/defaults/main.yml index 360f830..2fe5a64 100644 --- a/llm-server/llm/ansible/roles/gpt_researcher/defaults/main.yml +++ b/llm-server/llm/ansible/roles/gpt_researcher/defaults/main.yml @@ -36,10 +36,12 @@ gpt_researcher_engine_base_url: http://llama-cpp:8080/v1 gpt_researcher_engine_model_id: swift-1.5-qwen3.8-27b-q6k gpt_researcher_engine_api_key_secret: gptr-engine-api-key -# Shim (python:3.13-alpine, digest-gepinnt) maps gpt-researcher's -# RETRIEVER=custom contract (?query= -> [{"url","raw_content"}]) onto our -# SearXNG (?q=&format=json). The published gptr image lacks the duckduckgo -# lib (renamed to ddgs in 2026), so SearXNG via shim is the retriever. +# Shim (python:3.13-alpine, tag-gepinnt) maps gpt-researcher's +# RETRIEVER=custom contract (?query= -> [{"href","url","raw_content"}]) +# onto our SearXNG (?q=&format=json). The published gptr image lacks the +# duckduckgo lib (renamed to ddgs in 2026), so SearXNG via shim is the +# retriever. "href" is the key v3.8 actually reads when building the +# scrape list (skills/researcher.py: url.get("href")). gpt_researcher_shim_image: docker.io/library/python # Tag-ref (Pull=never + pre-pull by tag in the role): the manifest-list # digest of 3.13-alpine 404s on direct pull, so we pin the tag and pull it @@ -58,6 +60,9 @@ gpt_researcher_env: RETRIEVER: custom RETRIEVERS: custom RETRIEVER_ENDPOINT: http://gptr-searxng-shim:8099/ + # v3.8 default scraper is "bs" (requests + bs4) — pin it explicitly so a + # future upstream default change cannot require a browser in the image + SCRAPER: bs LLM_TIMEOUT: "600" LOGGING_LEVEL: INFO DOC_PATH: /usr/src/app/my-docs diff --git a/llm-server/llm/ansible/roles/gpt_researcher/files/searxng_shim.py b/llm-server/llm/ansible/roles/gpt_researcher/files/searxng_shim.py index bc3313a..f08f926 100644 --- a/llm-server/llm/ansible/roles/gpt_researcher/files/searxng_shim.py +++ b/llm-server/llm/ansible/roles/gpt_researcher/files/searxng_shim.py @@ -1,11 +1,19 @@ #!/usr/bin/env python3 """Shim between gpt-researcher's RETRIEVER=custom and SearXNG. -gpt-researcher custom retriever: GET ?query= (+ extra -params), expects a JSON list of {"url", "raw_content"}. If raw_content is -longer than 100 chars, gpt-researcher SKIPS its own (broken-in-image) -scraper and uses raw_content directly. So this shim fetches each result page -itself and returns the text — no scraping on the gptr side needed. +gpt-researcher v3.8 custom retriever: GET ?query= +(+ extra params), expects a JSON list of result dicts. IMPORTANT: v3.8 +builds the scrape list via `url.get("href")` in +skills/researcher.py::_search_relevant_source_urls — the key must be +"href" (returning only "url" yields None entries and the scraper crashes +with "Error processing None ... endswith"). "url"/"raw_content" are kept +for compatibility; v3.8 does NOT skip its own scraper based on +raw_content — the backend re-fetches every href with the default "bs" +scraper (requests + bs4, no browser needed in the image). + +The pre-fetch here therefore only filters dead/unfetchable result pages +(raw text <= 100 chars are dropped) so the gptr scraper does not waste +workers on them. SearXNG side: /search?q=&format=json -> {"results": [...]}. Listens on :8099, internal networks only (no published port). @@ -64,13 +72,12 @@ class Handler(BaseHTTPRequestHandler): if not u or not isinstance(u, str): continue content = fetch_text(u) - # only pass pages we actually fetched: raw_content > 100 chars - # makes gpt-researcher skip its own (broken-in-image) scraper; - # short/empty content would trigger the scraper crash - # ("Error processing None ... endswith", Scraped 0 pages) + # only pass pages we actually fetched (raw text > 100 chars); + # v3.8 reads "href" to build the scrape list, so without it the + # scraper receives None and crashes ("Error processing None") if len(content) <= 100: continue - out.append({"url": u, "raw_content": content}) + out.append({"href": u, "url": u, "raw_content": content}) if len(out) >= MAX_RESULTS: break body = json.dumps(out).encode()