From 69305f664b3419525fbaac3c49d1b5e2457fe706 Mon Sep 17 00:00:00 2001 From: spektr Date: Sun, 22 Nov 2026 02:55:22 +0100 Subject: [PATCH] =?UTF-8?q?GNAI-023=20M8-T4=20Fix:=20leere=20Reports=20?= =?UTF-8?q?=E2=80=94=20Reasoning=20frisst=20max=5Ftokens-Budget?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- llm-server/llm/ansible/playbooks/research.yml | 4 +++ .../roles/gpt_researcher/defaults/main.yml | 5 ++++ .../files/sitecustomize_gnai.py | 25 +++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/llm-server/llm/ansible/playbooks/research.yml b/llm-server/llm/ansible/playbooks/research.yml index a1d36c0..56afd2c 100644 --- a/llm-server/llm/ansible/playbooks/research.yml +++ b/llm-server/llm/ansible/playbooks/research.yml @@ -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 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 32bdb6d..2642c34 100644 --- a/llm-server/llm/ansible/roles/gpt_researcher/defaults/main.yml +++ b/llm-server/llm/ansible/roles/gpt_researcher/defaults/main.yml @@ -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 diff --git a/llm-server/llm/ansible/roles/gpt_researcher/files/sitecustomize_gnai.py b/llm-server/llm/ansible/roles/gpt_researcher/files/sitecustomize_gnai.py index 3dafee4..e8e848e 100644 --- a/llm-server/llm/ansible/roles/gpt_researcher/files/sitecustomize_gnai.py +++ b/llm-server/llm/ansible/roles/gpt_researcher/files/sitecustomize_gnai.py @@ -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