GNAI-023 M8-T4 Fix: leere Reports — Reasoning frisst max_tokens-Budget

Bei großem Report-Prompt verbrauchte das Denken (engine reasoning xhigh) das
gesamte clientseitige max_tokens (Reasoning+Content gemeinsam begrenzt) ->
Report kam leer zurueck (md 0 Bytes, pdf/docx nur Boilerplate). Fix:
sitecustomize wrappt create_chat_completion und injiziert
extra_body.chat_template_kwargs.enable_thinking=false (llama.cpp --jinja),
plus Token-Limits FAST 4000 / SMART+STRATEGIC 16000. force_handlers in
research.yml gegen stale Single-File-Bind-Mounts. Verifiziert: gepatchter
Call antwortet in 0,4 s mit Inhalt, md5 des Mounts stimmt.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
2026-11-22 02:55:22 +01:00
parent 8ef591b4a0
commit 69305f664b
3 changed files with 34 additions and 0 deletions
@@ -9,5 +9,9 @@
- name: Deploy the GPT Researcher harness for the Production environment
hosts: llm_servers
become: true
# single-file bind mounts (sitecustomize.py) keep the old inode when the
# copy task replaces the file — the restart handler must run even if a
# later verification task fails, else the container serves a stale patch
force_handlers: true
roles:
- role: gpt_researcher
@@ -91,6 +91,11 @@ gpt_researcher_env:
# GNAI_EMBEDDING_BASE_URL (CPU-only llama-cpp sidecar, alias llama-cpp-embed)
EMBEDDING: "custom:{{ gpt_researcher_embed_model_alias }}"
GNAI_EMBEDDING_BASE_URL: "{{ gpt_researcher_embed_base_url }}"
# headroom for report generation (sitecustomize disables thinking, so the
# budget goes to content; 16000 is the v3.8 hard cap)
FAST_TOKEN_LIMIT: "4000"
SMART_TOKEN_LIMIT: "16000"
STRATEGIC_TOKEN_LIMIT: "16000"
LLM_TIMEOUT: "600"
LOGGING_LEVEL: INFO
DOC_PATH: /usr/src/app/my-docs
@@ -59,3 +59,28 @@ try:
_bu.write_md_to_pdf = _write_md_to_pdf_weasyprint
except Exception:
pass
# gpt-researcher LLM calls: the engine profile runs with reasoning enabled and
# the client-side max_tokens caps reasoning+content TOGETHER. On large report
# prompts the reasoning alone exhausts the budget, so the report comes back
# EMPTY (no streamed chunks, md/pdf/docx 0 bytes). Force enable_thinking=false
# via chat_template_kwargs (llama.cpp --jinja honors it, verified 2026-11-22:
# 3 vs 97 completion tokens) so the budget goes to visible content.
# sitecustomize runs before any gpt_researcher module import, so replacing the
# attribute here covers all `from ...utils.llm import create_chat_completion`.
try:
import gpt_researcher.utils.llm as _gllm
_orig_ccc = _gllm.create_chat_completion
async def _ccc_no_thinking(*args, **kwargs):
kw = dict(kwargs.get("llm_kwargs") or {})
extra = dict(kw.get("extra_body") or {})
extra["chat_template_kwargs"] = {"enable_thinking": False}
kw["extra_body"] = extra
kwargs["llm_kwargs"] = kw
return await _orig_ccc(*args, **kwargs)
_gllm.create_chat_completion = _ccc_no_thinking
except Exception:
pass