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