Skip to content

feat(data-analytics-demo): T-08 narrative — local Ollama LLM pipeline#88

Merged
leagames0221-sys merged 1 commit into
mainfrom
feat/data-analytics-demo-t08-narrative
May 17, 2026
Merged

feat(data-analytics-demo): T-08 narrative — local Ollama LLM pipeline#88
leagames0221-sys merged 1 commit into
mainfrom
feat/data-analytics-demo-t08-narrative

Conversation

@leagames0221-sys

Copy link
Copy Markdown
Owner

Summary

Phase 4 of the data-analytics-demo bolt-on. The package now produces an executive-facing narrative from the churn SHAP summary — entirely on a local Ollama daemon, with a runtime assertion that no cloud-LLM credential is in the environment.

What lands

Path Role
narrative/ollama_client.py OLLAMA_HOST / OLLAMA_MODEL env-var resolution; AC-4.3 credential-leak guard; AC-4.2 remediation hint on connection failure
narrative/prompts.py Executive-brief prompt template; SHAP → prompt is the only call point
narrative/generate.py Orchestration: SHAP JSON in → markdown out; provenance metadata wraps the LLM body (AC-4.4 + AC-4.5)
tests/test_narrative.py 7 cases (mock Ollama via monkeypatch) covering every AC plus missing-data + prompt builder
Makefile narrative + cli.py narrative Wired up

AC coverage

AC Behaviour Verified via
4.1 make narrative produces output.md test_ac_4_1_produces_output_markdown + real Ollama smoke
4.2 Ollama unreachable → clear remediation error test_ac_4_2_unreachable_ollama_clear_error
4.3 No external LLM API call; env-var guard trips before client test_ac_4_3_external_api_env_blocks_invocation + unit
4.4 Output cites shap_summary.json test_ac_4_4_and_4_5_metadata_block
4.5 Output contains the model identifier same test, asserts default model string

Defaults & overrides

  • OLLAMA_HOST defaults to http://localhost:11434
  • OLLAMA_MODEL defaults to llama3.1:8b-instruct-q4_K_M (literal AC-4.5 value)
  • Both are overridable for deployments that prefer a different quantized variant; AC-4.5's "or equivalent quantized variant" wording is honoured by the swap path.

Local verify

  • ruff + mypy --strict clean (14 source files)
  • pytest — 22 passed, coverage 87.20%
  • Real-Ollama smoke (with OLLAMA_MODEL=gemma3:4b, the model already pulled locally): end-to-end produces a 3-paragraph executive narrative; all 5 metadata fields present; no external network calls.

Test plan

  • Required CI checks green (existing 11 + python-test + python-audit)
  • No HIVE-token leaks (D-HIVE-OPACITY)

Phase 4 of the data-analytics-demo bolt-on. Reads the SHAP summary that the
ML layer (#87) writes, sends a templated prompt to a local Ollama daemon,
and saves an executive-facing markdown narrative — never touching a cloud
LLM API.

What lands:
- narrative/ollama_client.py — env-var-gated host/model resolution
  (defaults: localhost:11434 + llama3.1:8b-instruct-q4_K_M), AC-4.3
  assertion that no cloud-LLM credentials are present at invocation, AC-4.2
  remediation hint when Ollama is unreachable.
- narrative/prompts.py — the executive-brief prompt template; SHAP-summary
  rendering is the only call point.
- narrative/generate.py — orchestration. Reads shap_summary.json, builds
  the prompt, calls Ollama, wraps the body with provenance metadata
  (model id, SHAP source path, timestamp, "external calls: 0"
  assertion-enforced advertisement) — satisfies AC-4.1, AC-4.4, AC-4.5.
- tests/test_narrative.py — 7 cases covering AC-4.1〜4.5 plus missing-data
  and prompt-builder paths. Uses monkeypatch to stub `ollama.Client` so no
  network is required in CI.
- Makefile narrative target + cli.py narrative subcommand wire-up.

AC coverage (mock-Ollama tests + real-Ollama smoke locally):
- AC-4.1 produces output.md     PASS
- AC-4.2 unreachable Ollama     PASS (clear RuntimeError with "ollama serve" hint)
- AC-4.3 external API guard     PASS (raises before any client call)
- AC-4.4 cites shap_summary.json PASS
- AC-4.5 model identifier in output PASS

Local verify:
- ruff OK / mypy OK (14 source files) / pytest 22 PASS / coverage 87.20%
- Real smoke vs Ollama (gemma3:4b, env-var override): 3-paragraph
  executive narrative produced end-to-end, all metadata fields present.

Design note: the literal AC-4.5 default model name is preserved as the
package default; deployments running a different quantized variant can
override via the OLLAMA_MODEL env var without code changes.
@vercel

vercel Bot commented May 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
craftstack-collab Ready Ready Preview, Comment May 17, 2026 2:28pm
craftstack-knowledge Ready Ready Preview, Comment May 17, 2026 2:28pm

@leagames0221-sys leagames0221-sys merged commit a7e42fe into main May 17, 2026
12 checks passed
@leagames0221-sys leagames0221-sys deleted the feat/data-analytics-demo-t08-narrative branch May 17, 2026 14:42
leagames0221-sys added a commit that referenced this pull request May 21, 2026
…#88)

Phase 4 of the data-analytics-demo bolt-on. Reads the SHAP summary that the
ML layer (#87) writes, sends a templated prompt to a local Ollama daemon,
and saves an executive-facing markdown narrative — never touching a cloud
LLM API.

What lands:
- narrative/ollama_client.py — env-var-gated host/model resolution
  (defaults: localhost:11434 + llama3.1:8b-instruct-q4_K_M), AC-4.3
  assertion that no cloud-LLM credentials are present at invocation, AC-4.2
  remediation hint when Ollama is unreachable.
- narrative/prompts.py — the executive-brief prompt template; SHAP-summary
  rendering is the only call point.
- narrative/generate.py — orchestration. Reads shap_summary.json, builds
  the prompt, calls Ollama, wraps the body with provenance metadata
  (model id, SHAP source path, timestamp, "external calls: 0"
  assertion-enforced advertisement) — satisfies AC-4.1, AC-4.4, AC-4.5.
- tests/test_narrative.py — 7 cases covering AC-4.1〜4.5 plus missing-data
  and prompt-builder paths. Uses monkeypatch to stub `ollama.Client` so no
  network is required in CI.
- Makefile narrative target + cli.py narrative subcommand wire-up.

AC coverage (mock-Ollama tests + real-Ollama smoke locally):
- AC-4.1 produces output.md     PASS
- AC-4.2 unreachable Ollama     PASS (clear RuntimeError with "ollama serve" hint)
- AC-4.3 external API guard     PASS (raises before any client call)
- AC-4.4 cites shap_summary.json PASS
- AC-4.5 model identifier in output PASS

Local verify:
- ruff OK / mypy OK (14 source files) / pytest 22 PASS / coverage 87.20%
- Real smoke vs Ollama (gemma3:4b, env-var override): 3-paragraph
  executive narrative produced end-to-end, all metadata fields present.

Design note: the literal AC-4.5 default model name is preserved as the
package default; deployments running a different quantized variant can
override via the OLLAMA_MODEL env var without code changes.

Co-authored-by: leagames0221-sys <leagames0221@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant