Sync from GitHub: 55aea810e7ec84dc986cbe861bdfd9a8d2e3c60d
Browse files
app.py
CHANGED
|
@@ -708,18 +708,31 @@ organism.set_concept_extractor(_bitnet_concept_extractor)
|
|
| 708 |
logger.info("NuWave concept helper wired: dual-pass extraction live")
|
| 709 |
|
| 710 |
|
| 711 |
-
# ββ Substrate context formatter ββββββββββββββββββββββββ
|
| 712 |
-
#
|
| 713 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 714 |
# Group surfaced content by node-kind via ID prefix:
|
| 715 |
# tree_* β "Related concepts" (concept words from dual-pass)
|
| 716 |
# exp_* β "Prior questions on this topic" (deposit nodes)
|
| 717 |
# resp_* β "Prior responses"
|
| 718 |
# concept_narr_* β operational telemetry, omitted from prompt
|
| 719 |
-
# (it's substrate self-monitoring, not knowledge)
|
| 720 |
# other β "Other context"
|
| 721 |
-
# The "Dave Plummer Tempest analog" for LLM presentation: curated
|
| 722 |
-
# typed input vs. raw mush. See feedback_substrate_representation_first.md.
|
| 723 |
|
| 724 |
def _format_substrate_context(pith_context, pith_ids=None) -> str:
|
| 725 |
"""Return a sectioned substrate-context string for prompt injection."""
|
|
@@ -795,9 +808,11 @@ def on_send(message, history):
|
|
| 795 |
# doesn't need both. Recent messages pass verbatim (the model needs
|
| 796 |
# immediate context). Older messages are replaced by substrate context.
|
| 797 |
if pith_context:
|
| 798 |
-
substrate_ctx =
|
| 799 |
-
if
|
| 800 |
-
sys_ctx = substrate_ctx + "\n\n" + sys_ctx
|
|
|
|
|
|
|
| 801 |
|
| 802 |
# Build prompt β Pith context replaces old history
|
| 803 |
# Only send recent messages. The substrate carries the rest.
|
|
@@ -1034,11 +1049,10 @@ def on_benchmark(num_turns):
|
|
| 1034 |
sys_ctx = kiss_r.get("system_context", system_prompt)
|
| 1035 |
|
| 1036 |
# Pith Born rule extraction from substrate
|
| 1037 |
-
pith_context
|
| 1038 |
if pith_context:
|
| 1039 |
-
substrate_ctx =
|
| 1040 |
-
if substrate_ctx
|
| 1041 |
-
sys_ctx = substrate_ctx + "\n\n" + sys_ctx if sys_ctx else substrate_ctx
|
| 1042 |
|
| 1043 |
# Trim old messages β always, not gated on Pith.
|
| 1044 |
# The substrate + KISS carry what the older messages contained.
|
|
@@ -1286,9 +1300,8 @@ def on_interleaved_benchmark(
|
|
| 1286 |
kiss_r = nw_kiss_inst.filter_context(nw_msgs, system_prompt)
|
| 1287 |
sys_ctx = kiss_r.get("system_context", system_prompt)
|
| 1288 |
if pith_context:
|
| 1289 |
-
substrate_ctx =
|
| 1290 |
-
if substrate_ctx
|
| 1291 |
-
sys_ctx = substrate_ctx + "\n\n" + sys_ctx if sys_ctx else substrate_ctx
|
| 1292 |
|
| 1293 |
recent_window = 6
|
| 1294 |
recent = nw_msgs[-recent_window:] if len(nw_msgs) > recent_window else nw_msgs
|
|
|
|
| 708 |
logger.info("NuWave concept helper wired: dual-pass extraction live")
|
| 709 |
|
| 710 |
|
| 711 |
+
# ββ Substrate context formatter β DORMANT ββββββββββββββββββββββββ
|
| 712 |
+
#
|
| 713 |
+
# Status: NOT CALLED at any site as of 2026-04-28 (B1 reverted).
|
| 714 |
+
# Run 26 (commits 59124dd + e2c4343 active) showed B1's section
|
| 715 |
+
# headers added ~120-200 tokens of pure formatting overhead per
|
| 716 |
+
# turn β more than the typed-presentation benefit gave back at
|
| 717 |
+
# BitNet 1.58-bit 2B-parameter scale. Token economy regressed
|
| 718 |
+
# from -2.4% (Run 25) to +3.4% (Run 26). Reverted to plain
|
| 719 |
+
# "\n".join(pith_context) at all three call sites.
|
| 720 |
+
#
|
| 721 |
+
# Hypothesis worth revisiting at larger model scale (7B+ or
|
| 722 |
+
# higher-precision quantization): typed input may genuinely help
|
| 723 |
+
# attention when the model has more capacity to use the structural
|
| 724 |
+
# cues. At 2B / 1.58-bit, the formatting tax exceeds the benefit.
|
| 725 |
+
#
|
| 726 |
+
# The helper is preserved here as dormant code. Re-enable by
|
| 727 |
+
# swapping the three call sites back to:
|
| 728 |
+
# substrate_ctx = _format_substrate_context(pith_context, pith_ids)
|
| 729 |
+
# (and switching pith_extract β pith_extract_with_ids at sites 1 and 2).
|
| 730 |
# Group surfaced content by node-kind via ID prefix:
|
| 731 |
# tree_* β "Related concepts" (concept words from dual-pass)
|
| 732 |
# exp_* β "Prior questions on this topic" (deposit nodes)
|
| 733 |
# resp_* β "Prior responses"
|
| 734 |
# concept_narr_* β operational telemetry, omitted from prompt
|
|
|
|
| 735 |
# other β "Other context"
|
|
|
|
|
|
|
| 736 |
|
| 737 |
def _format_substrate_context(pith_context, pith_ids=None) -> str:
|
| 738 |
"""Return a sectioned substrate-context string for prompt injection."""
|
|
|
|
| 808 |
# doesn't need both. Recent messages pass verbatim (the model needs
|
| 809 |
# immediate context). Older messages are replaced by substrate context.
|
| 810 |
if pith_context:
|
| 811 |
+
substrate_ctx = "\n".join(pith_context)
|
| 812 |
+
if sys_ctx:
|
| 813 |
+
sys_ctx = substrate_ctx + "\n\n" + sys_ctx
|
| 814 |
+
else:
|
| 815 |
+
sys_ctx = substrate_ctx
|
| 816 |
|
| 817 |
# Build prompt β Pith context replaces old history
|
| 818 |
# Only send recent messages. The substrate carries the rest.
|
|
|
|
| 1049 |
sys_ctx = kiss_r.get("system_context", system_prompt)
|
| 1050 |
|
| 1051 |
# Pith Born rule extraction from substrate
|
| 1052 |
+
pith_context = nw_organism.pith_extract(prompt_text, max_context=5)
|
| 1053 |
if pith_context:
|
| 1054 |
+
substrate_ctx = "\n".join(pith_context)
|
| 1055 |
+
sys_ctx = substrate_ctx + "\n\n" + sys_ctx if sys_ctx else substrate_ctx
|
|
|
|
| 1056 |
|
| 1057 |
# Trim old messages β always, not gated on Pith.
|
| 1058 |
# The substrate + KISS carry what the older messages contained.
|
|
|
|
| 1300 |
kiss_r = nw_kiss_inst.filter_context(nw_msgs, system_prompt)
|
| 1301 |
sys_ctx = kiss_r.get("system_context", system_prompt)
|
| 1302 |
if pith_context:
|
| 1303 |
+
substrate_ctx = "\n".join(pith_context)
|
| 1304 |
+
sys_ctx = substrate_ctx + "\n\n" + sys_ctx if sys_ctx else substrate_ctx
|
|
|
|
| 1305 |
|
| 1306 |
recent_window = 6
|
| 1307 |
recent = nw_msgs[-recent_window:] if len(nw_msgs) > recent_window else nw_msgs
|