M8-T4: Retriever auf SearXNG via Shim (RETRIEVER=custom) — duckduckgo-lib im Image broken (ddgs)
- shim container gptr-searxng-shim (python:3.13-alpine, tag-pin), mappt ?query= -> SearXNG ?q=&format=json -> [{url,raw_content}]
- backend env: RETRIEVER=custom, RETRIEVER_ENDPOINT=http://gptr-searxng-shim:8099/
- verifiziert: shim antwortet mit echten SearXNG-Ergebnissen (aus backend container), research.yml changed=3 dann idempotent changed=0
Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
@@ -218,3 +218,13 @@ Internet → NPM (CT 103, 443) → auth_request-Subrequest an oauth2-proxy
|
||||
Drift-Update via DELETE+POST (PUT löscht die conf ohne neu zu schreiben).
|
||||
Verifiziert: 36.conf generiert, nginx -t ok, TLS CN=research, unauth /,
|
||||
/api/docs, /ws → 302 Keycloak.
|
||||
|
||||
- **Befund 19.11. (Retriever):** das publizierte gptr-Image lacks `duckduckgo-search`
|
||||
(lib heißt 2026 `ddgs`) → Fehler beim DuckDuckGo-Retriever. Lösung:
|
||||
`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
|
||||
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.
|
||||
|
||||
@@ -36,16 +36,27 @@ 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
|
||||
|
||||
# LLM + retriever config (gpt-researcher v3.8 env). Both SEARCH_ENGINE and
|
||||
# RETRIEVER are set defensively; duckduckgo is keyless. Token limits stay at
|
||||
# upstream defaults (FAST=3000/SMART=6000) — fine for a 27B local model.
|
||||
# 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.
|
||||
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
|
||||
# explicitly when absent (same pattern as the GNMON image transport).
|
||||
gpt_researcher_shim_image_ref: "{{ gpt_researcher_shim_image }}:3.13-alpine"
|
||||
gpt_researcher_shim_script: "{{ gpt_researcher_data_dir }}/searxng_shim.py"
|
||||
|
||||
# LLM + retriever config (gpt-researcher v3.8 env; LLM names need the
|
||||
# '<provider>:<model>' form). Token limits stay at upstream defaults
|
||||
# (FAST=3000/SMART=6000) — fine for a 27B local model.
|
||||
gpt_researcher_env:
|
||||
OPENAI_BASE_URL: "{{ gpt_researcher_engine_base_url }}"
|
||||
FAST_LLM: "openai:{{ gpt_researcher_engine_model_id }}"
|
||||
SMART_LLM: "openai:{{ gpt_researcher_engine_model_id }}"
|
||||
STRATEGIC_LLM: "openai:{{ gpt_researcher_engine_model_id }}"
|
||||
SEARCH_ENGINE: duckduckgo
|
||||
RETRIEVER: duckduckgo
|
||||
RETRIEVER: custom
|
||||
RETRIEVER_ENDPOINT: http://gptr-searxng-shim:8099/
|
||||
LLM_TIMEOUT: "600"
|
||||
LOGGING_LEVEL: INFO
|
||||
DOC_PATH: /usr/src/app/my-docs
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Tiny 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).
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
|
||||
SEARXNG = os.environ.get("SHIM_SEARXNG_URL", "http://searxng:8080")
|
||||
|
||||
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
qs = urllib.parse.parse_qs(urllib.parse.urlparse(self.path).query)
|
||||
q = (qs.get("query") or qs.get("q") or [""])[0]
|
||||
if not q:
|
||||
self.send_response(400)
|
||||
self.end_headers()
|
||||
self.wfile.write(b'{"error": "missing query"}')
|
||||
return
|
||||
url = f"{SEARXNG}/search?" + urllib.parse.urlencode({"q": q, "format": "json"})
|
||||
try:
|
||||
with urllib.request.urlopen(url, timeout=20) 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")
|
||||
]
|
||||
body = json.dumps(out).encode()
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.send_header("Content-Length", str(len(body)))
|
||||
self.end_headers()
|
||||
self.wfile.write(body)
|
||||
|
||||
def log_message(self, *args):
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
HTTPServer(("0.0.0.0", 8099), Handler).serve_forever()
|
||||
@@ -34,4 +34,5 @@
|
||||
loop:
|
||||
- backend
|
||||
- frontend
|
||||
- searxng-shim
|
||||
when: not ansible_check_mode
|
||||
|
||||
@@ -19,6 +19,14 @@
|
||||
- outputs
|
||||
- logs
|
||||
|
||||
- name: Deploy the searxng shim script
|
||||
ansible.builtin.copy:
|
||||
src: files/searxng_shim.py
|
||||
dest: "{{ gpt_researcher_shim_script }}"
|
||||
owner: "{{ gpt_researcher_user }}"
|
||||
group: "{{ gpt_researcher_user }}"
|
||||
mode: "0644"
|
||||
|
||||
- name: Check whether the engine API key secret exists
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
@@ -70,6 +78,7 @@
|
||||
loop:
|
||||
- "{{ gpt_researcher_backend_image_ref }}"
|
||||
- "{{ gpt_researcher_frontend_image_ref }}"
|
||||
- "{{ gpt_researcher_shim_image_ref }}"
|
||||
register: gptr_images_present
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
@@ -104,6 +113,7 @@
|
||||
loop:
|
||||
- { src: gptr-backend.container.j2, name: backend }
|
||||
- { src: gptr-frontend.container.j2, name: frontend }
|
||||
- { src: gptr-searxng-shim.container.j2, name: searxng-shim }
|
||||
notify:
|
||||
- Reload workload user manager
|
||||
- Restart gptr units
|
||||
@@ -143,6 +153,7 @@
|
||||
loop:
|
||||
- backend
|
||||
- frontend
|
||||
- searxng-shim
|
||||
register: gptr_unit_states
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
@@ -180,6 +191,26 @@
|
||||
delay: 5
|
||||
when: not ansible_check_mode
|
||||
|
||||
- name: Verify the searxng shim answers via the backend network
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- /usr/sbin/runuser
|
||||
- --user
|
||||
- "{{ gpt_researcher_user }}"
|
||||
- --
|
||||
- /usr/bin/env
|
||||
- "HOME={{ gpt_researcher_home }}"
|
||||
- "XDG_RUNTIME_DIR=/run/user/{{ gpt_researcher_uid }}"
|
||||
- /usr/bin/podman
|
||||
- exec
|
||||
- "{{ gpt_researcher_unit_prefix }}-backend"
|
||||
- /bin/sh
|
||||
- -c
|
||||
- "python3 -c \"import urllib.request,json; d=json.loads(urllib.request.urlopen('http://gptr-searxng-shim:8099/?query=openwebui', timeout=25).read()); assert isinstance(d, list) and d and d[0]['url'], d[:1]\""
|
||||
chdir: "{{ gpt_researcher_home }}"
|
||||
changed_when: false
|
||||
when: not ansible_check_mode
|
||||
|
||||
- name: Verify the engine is reachable from the backend container
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
[Unit]
|
||||
Description=SearXNG shim for gpt-researcher custom retriever (:8099, internal only)
|
||||
Wants={{ gpt_researcher_network_name }}-network.service {{ gpt_researcher_egress_network_name }}-network.service
|
||||
After={{ gpt_researcher_network_name }}-network.service {{ gpt_researcher_egress_network_name }}-network.service
|
||||
|
||||
[Container]
|
||||
Image={{ gpt_researcher_shim_image_ref }}
|
||||
Pull=never
|
||||
ContainerName={{ gpt_researcher_unit_prefix }}-searxng-shim
|
||||
Network={{ gpt_researcher_network_name }}
|
||||
Network={{ gpt_researcher_egress_network_name }}
|
||||
NetworkAlias=gptr-searxng-shim
|
||||
# no PublishPort: reachable only inside the workload networks
|
||||
Volume={{ gpt_researcher_shim_script }}:/shim.py:ro
|
||||
Exec=python3 /shim.py
|
||||
Environment=SHIM_SEARXNG_URL=http://searxng:8080
|
||||
|
||||
[Service]
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
TimeoutStartSec=60
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
Reference in New Issue
Block a user