M6-R1 (GNAI-022 Deep Research) + M8 (GNAI-023 GPT Researcher hinter oauth2-proxy/IAP) — 31 lokale Commits #20

Merged
spektr merged 31 commits from m8/gnai-022-023-deepresearch-gptr-iap into main 2026-11-25 16:32:58 +01:00
3 changed files with 48 additions and 12 deletions
Showing only changes of commit 8cb33c7810 - Show all commits
@@ -228,3 +228,10 @@ Internet → NPM (CT 103, 443) → auth_request-Subrequest an oauth2-proxy
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.
@@ -1,19 +1,43 @@
#!/usr/bin/env python3
"""Tiny shim between gpt-researcher's RETRIEVER=custom and SearXNG.
"""Shim between gpt-researcher's RETRIEVER=custom and SearXNG.
gpt-researcher custom retriever does: GET <RETRIEVER_ENDPOINT>?query=<q>
(+ RETRIEVER_ARG_* as extra params) and expects a JSON list of
{"url", "raw_content"}. SearXNG wants /search?q=<q>&format=json and returns
{"results": [...]}. This shim maps between the two. Listens on :8099,
internal network only (no published port).
gpt-researcher custom retriever: GET <RETRIEVER_ENDPOINT>?query=<q> (+ 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.
SearXNG side: /search?q=<q>&format=json -> {"results": [...]}.
Listens on :8099, internal networks only (no published port).
"""
import json
import os
import re
import urllib.parse
import urllib.request
from http.server import BaseHTTPRequestHandler, HTTPServer
SEARXNG = os.environ.get("SHIM_SEARXNG_URL", "http://searxng:8080")
UA = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 Chrome/131.0 Safari/537.36"
MAX_RESULTS = int(os.environ.get("SHIM_MAX_RESULTS", "8"))
FETCH_TIMEOUT = 10
MAX_BODY = 200_000
def fetch_text(url):
try:
req = urllib.request.Request(url, headers={"User-Agent": UA})
with urllib.request.urlopen(req, timeout=FETCH_TIMEOUT) as resp:
ctype = resp.headers.get("content-type", "")
if "html" not in ctype and "text" not in ctype:
return ""
raw = resp.read(MAX_BODY).decode("utf-8", errors="replace")
text = re.sub(r"(?is)<(script|style|nav|footer|header|svg)[^>]*>.*?</\1>", " ", raw)
text = re.sub(r"(?s)<[^>]+>", " ", text)
text = re.sub(r"\s+", " ", text).strip()
return text[:8000]
except Exception:
return ""
class Handler(BaseHTTPRequestHandler):
@@ -27,18 +51,20 @@ class Handler(BaseHTTPRequestHandler):
return
url = f"{SEARXNG}/search?" + urllib.parse.urlencode({"q": q, "format": "json"})
try:
with urllib.request.urlopen(url, timeout=20) as resp:
with urllib.request.urlopen(url, timeout=25) as resp:
data = json.loads(resp.read())
except Exception as e:
self.send_response(502)
self.end_headers()
self.wfile.write(json.dumps({"error": str(e)}).encode())
return
out = [
{"url": r.get("url", ""), "raw_content": r.get("content", "")}
for r in data.get("results", [])
if r.get("url")
]
out = []
for r in data.get("results", [])[:MAX_RESULTS]:
u = r.get("url", "")
if not u:
continue
content = fetch_text(u) or (r.get("content") or "")
out.append({"url": u, "raw_content": content})
body = json.dumps(out).encode()
self.send_response(200)
self.send_header("Content-Type", "application/json")
@@ -26,6 +26,9 @@
owner: "{{ gpt_researcher_user }}"
group: "{{ gpt_researcher_user }}"
mode: "0644"
notify:
- Reload workload user manager
- Restart gptr units
- name: Check whether the engine API key secret exists
ansible.builtin.command: