M6-R1: Stream-Abbruch bei Deep Research fixen (max_tokens-Limit, parallele Fetches, Heartbeat)
Ursache "Verbindung zum Server fehlgeschlagen": Engine-Calls ohne max_tokens liefen unter xhigh bis n_predict=32768, Stream war stumm, NPM proxy_read_timeout (600s) griff. Fix: Valve MAX_TOKENS (default 4096) pro Engine-Call + HTTP-Timeout gekoppelt, Fetches parallel via asyncio.gather, Status-Heartbeat vor jedem Engine-Call. sha256-Pin 45cb3be0...; deployt changed=1 dann idempotent changed=0; DB verifiziert. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
@@ -39,7 +39,7 @@ open_webui_web_search_tool_id: gnai-web-search
|
||||
# sha256 (recompute after every edit of files/gnai-deep-research-pipe.py:
|
||||
# sha256sum files/gnai-deep-research-pipe.py).
|
||||
open_webui_deep_research_function_id: gnai-deep-research
|
||||
open_webui_deep_research_pipe_sha256: "5ddb6191c7e94789d2e1bf33b775092a38d6fe5c5762653d07084dcc58a9b677"
|
||||
open_webui_deep_research_pipe_sha256: "45cb3be0029937fdde7d70018d63191101fba8151dcf55e5566c464584b54c9b"
|
||||
open_webui_deep_research_valves:
|
||||
ENGINE_BASE_URL: "{{ open_webui_engine_base_url }}"
|
||||
ENGINE_MODEL_ID: "{{ open_webui_engine_model_id }}"
|
||||
@@ -50,6 +50,8 @@ open_webui_deep_research_valves:
|
||||
PAGES_PER_ROUND: 5
|
||||
FETCH_TIMEOUT_S: 12.0
|
||||
FETCH_MAX_BYTES: 200000
|
||||
PAGE_TEXT_CHARS: 5000
|
||||
MAX_TOKENS: 4096
|
||||
TEMPERATURE: 0.3
|
||||
|
||||
# Engine endpoint inside the shared Production network. llama.cpp itself
|
||||
|
||||
@@ -5,6 +5,7 @@ description: Iterativer Deep-Research-Loop (plan -> SearXNG-Suche -> Seiten-Fetc
|
||||
license: MIT
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import ipaddress
|
||||
import json
|
||||
import re
|
||||
@@ -63,6 +64,20 @@ class Pipe:
|
||||
PAGES_PER_ROUND: int = Field(default=5, ge=1, le=10)
|
||||
FETCH_TIMEOUT_S: float = Field(default=12.0, gt=0, le=60)
|
||||
FETCH_MAX_BYTES: int = Field(default=200_000, ge=10_000, le=1_000_000)
|
||||
PAGE_TEXT_CHARS: int = Field(
|
||||
default=5000,
|
||||
ge=1000,
|
||||
le=20000,
|
||||
description="Textlaenge pro gefetchter Seite im Synthese-Kontext.",
|
||||
)
|
||||
MAX_TOKENS: int = Field(
|
||||
default=4096,
|
||||
ge=512,
|
||||
le=16384,
|
||||
description="max_tokens pro Engine-Call. Wichtig: ohne Limit laeuft das "
|
||||
"xhigh-Profil bis n_predict (32k) und der NPM proxy_read_timeout (600 s) "
|
||||
"bricht den Stream ab.",
|
||||
)
|
||||
TEMPERATURE: float = Field(default=0.3, ge=0, le=2)
|
||||
|
||||
def __init__(self):
|
||||
@@ -135,7 +150,11 @@ class Pipe:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
async def _engine(self, client: httpx.AsyncClient, messages: list[dict]) -> str:
|
||||
async def _engine(self, client: httpx.AsyncClient, messages: list[dict], emitter: Any = None) -> str:
|
||||
# max_tokens begrenzt JEDEN Engine-Call: das xhigh-Profil denkt sonst
|
||||
# bis n_predict (32k) und der NPM-Read-Timeout killt den Stream.
|
||||
if emitter is not None:
|
||||
await self._emit(emitter, "Engine-Antwort wird erzeugt (max_tokens begrenzt) …")
|
||||
resp = await client.post(
|
||||
f"{self.valves.ENGINE_BASE_URL.rstrip('/')}/chat/completions",
|
||||
json={
|
||||
@@ -143,8 +162,9 @@ class Pipe:
|
||||
"messages": messages,
|
||||
"temperature": self.valves.TEMPERATURE,
|
||||
"stream": False,
|
||||
"max_tokens": self.valves.MAX_TOKENS,
|
||||
},
|
||||
timeout=180.0,
|
||||
timeout=max(120.0, self.valves.MAX_TOKENS / 5.0),
|
||||
)
|
||||
resp.raise_for_status()
|
||||
data = resp.json()
|
||||
@@ -248,7 +268,7 @@ class Pipe:
|
||||
{"role": "user", "content": f"Research question: {question}"},
|
||||
]
|
||||
await self._emit(__event_emitter__, f"Runde {round_no}: plane Suchanfragen …")
|
||||
plan = self._extract_json(await self._engine(client, plan_msgs))
|
||||
plan = self._extract_json(await self._engine(client, plan_msgs, __event_emitter__))
|
||||
queries = [q for q in plan.get("queries", []) if isinstance(q, str)][: v.QUERIES_PER_ROUND]
|
||||
if not queries:
|
||||
queries = [question]
|
||||
@@ -263,14 +283,16 @@ class Pipe:
|
||||
r["query"] = q
|
||||
found.append(r)
|
||||
|
||||
# 3) Top-Seiten fetchen (mit SSRF-Guard)
|
||||
pages: list[dict] = []
|
||||
for r in found[: v.PAGES_PER_ROUND]:
|
||||
# 3) Top-Seiten parallel fetchen (mit SSRF-Guard)
|
||||
targets = found[: v.PAGES_PER_ROUND]
|
||||
for r in targets:
|
||||
await self._emit(__event_emitter__, f"Lese {r['url'][:100]} …")
|
||||
text = await self._fetch(client, r["url"])
|
||||
texts = await asyncio.gather(*(self._fetch(client, r["url"]) for r in targets))
|
||||
pages: list[dict] = []
|
||||
for r, text in zip(targets, texts):
|
||||
if text:
|
||||
sources.append({"n": len(sources) + 1, "url": r["url"], "title": r["title"] or r["url"]})
|
||||
pages.append({"n": sources[-1]["n"], "url": r["url"], "title": sources[-1]["title"], "text": text[:8000]})
|
||||
pages.append({"n": sources[-1]["n"], "url": r["url"], "title": sources[-1]["title"], "text": text[: v.PAGE_TEXT_CHARS]})
|
||||
|
||||
findings = "\n\n".join(
|
||||
f"[{p['n']}] {p['title']} ({p['url']})\n{p['text']}" for p in pages
|
||||
@@ -286,7 +308,7 @@ class Pipe:
|
||||
{"role": "user", "content": f"Research question: {question}\n\nSearch-result snippets:\n{snippets}\n\nFetched pages:\n{findings}"},
|
||||
]
|
||||
await self._emit(__event_emitter__, f"Runde {round_no}: synthetisiere Zwischenergebnis …")
|
||||
verdict = self._extract_json(await self._engine(client, synth_msgs))
|
||||
verdict = self._extract_json(await self._engine(client, synth_msgs, __event_emitter__))
|
||||
if verdict.get("status") == "done" and verdict.get("report"):
|
||||
report = str(verdict["report"])
|
||||
if sources:
|
||||
@@ -310,7 +332,7 @@ class Pipe:
|
||||
f"[{s['n']}] {s['title']} ({s['url']})" for s in sources
|
||||
)},
|
||||
]
|
||||
verdict = self._extract_json(await self._engine(client, final_msgs))
|
||||
verdict = self._extract_json(await self._engine(client, final_msgs, __event_emitter__))
|
||||
report = verdict.get("report") or "(kein Report erzeugt)"
|
||||
report += "\n\n## Quellen\n" + "\n".join(
|
||||
f"[{s['n']}] {s['title']} — {s['url']}" for s in sources
|
||||
|
||||
Reference in New Issue
Block a user