Skip to content

Commit c22c236

Browse files
authored
Merge PR #3: Bess Ollama battery tooling + Grok substrate fix
Bess Ollama battery tooling + Grok substrate fix
2 parents 3fe6a54 + fcdf027 commit c22c236

2 files changed

Lines changed: 142 additions & 3 deletions

File tree

tel_deploy/convergence_split.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,34 @@ def derive_paired_seed(
8787
# Azure content filter → L1 regardless of model version.
8888
# Open-weights deployments (DeepSeek, Kimi, etc.) → L2.
8989
# C-seed distinguishes constitutional behavior within the same B-substrate.
90+
#
91+
# NOTE: Grok (xAI) produces an all-L1 B-vector identical to azure_gpt.
92+
# Disambiguated via C-seed topology prefix: Llama-small (92de78db823f470e) → grok_xai.
93+
# Pass c_seed to identify_substrate() when available.
9094
KNOWN_FINGERPRINTS = {
9195
"azure_gpt": ["L1", "L1", "L1", "L1"], # Azure content filter (gpt-4o, gpt-5.x)
96+
"grok_xai": ["L1", "L1", "L1", "L1"], # xAI Grok — same B-vector, Llama-small topology
9297
"open_weights": ["L2", "L2", "L2", "L2"], # Unfiltered deployment (DeepSeek, Kimi)
9398
}
9499

100+
# C-seed prefixes that break B-vector ties between substrates with identical patterns.
101+
_LLAMA_SMALL_PREFIX = "92de78db823f470e"
95102

96-
def identify_substrate(b_vector: list) -> str:
97-
"""Identify the substrate from its B-fingerprint pattern."""
103+
104+
def identify_substrate(b_vector: list, c_seed: str = None) -> str:
105+
"""Identify the substrate from its B-fingerprint pattern.
106+
107+
Pass c_seed when available — required to distinguish grok_xai from azure_gpt,
108+
which share an identical all-L1 B-vector.
109+
"""
110+
all_l1 = ["L1", "L1", "L1", "L1"]
111+
if b_vector == all_l1:
112+
if c_seed and c_seed.startswith(_LLAMA_SMALL_PREFIX):
113+
return "grok_xai"
114+
return "azure_gpt"
98115
for name, pattern in KNOWN_FINGERPRINTS.items():
116+
if name in ("azure_gpt", "grok_xai"):
117+
continue # already handled above
99118
if b_vector == pattern:
100119
return name
101120
return f"unknown_{derive_b_fingerprint(b_vector)[:8]}"
@@ -117,7 +136,7 @@ def __init__(self, stable_vector: list, grammar_version: str = GRAMMAR_VERSION):
117136
self.c_vector, self.b_vector = split_vector(stable_vector)
118137
self.c_seed = derive_c_seed(self.c_vector, grammar_version)
119138
self.b_fingerprint = derive_b_fingerprint(self.b_vector)
120-
self.substrate = identify_substrate(self.b_vector)
139+
self.substrate = identify_substrate(self.b_vector, c_seed=self.c_seed)
121140

122141
def get_mesh_seed(self) -> str:
123142
"""Universal seed for mesh-wide encryption."""

test_ollama_local.py

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
"""
2+
TEL convergence battery — local Ollama endpoint.
3+
Usage: python3 test_ollama_local.py <model-name>
4+
Example: python3 test_ollama_local.py qwen2.5:7b
5+
"""
6+
7+
import asyncio
8+
import logging
9+
import os
10+
import sys
11+
12+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
13+
14+
from tel_deploy.convergence import ConvergenceDetector
15+
from tel_deploy.convergence_split import ConvergenceSplit, GRAMMAR_VERSION
16+
from tel_deploy.test_runner import run_convergence_pass
17+
18+
OLLAMA_ENDPOINT = "http://embassy.helixaiinnovations.ca:11434/v1/chat/completions"
19+
TIMEOUT = 300.0
20+
21+
logging.basicConfig(
22+
level=logging.INFO,
23+
format="[%(asctime)s] %(levelname)s %(name)s: %(message)s",
24+
)
25+
log = logging.getLogger("tel.ollama")
26+
27+
KNOWN_SEEDS = {
28+
"c9b0b4c41bb10069d2109b64d8ddad1037531031a93d17dd62de5bd7b2a6a1ac": "Universal",
29+
"92de78db823f470ece6f78e4a7fab31fb0392f7df2edd4f2bc71e1ad332ba727": "Llama-small",
30+
"18f54f0556a9f880": "Gemma-small",
31+
}
32+
33+
34+
def identify_topology(c_seed: str) -> str:
35+
for seed, name in KNOWN_SEEDS.items():
36+
if c_seed.startswith(seed):
37+
return name
38+
return "NEW — unclassified"
39+
40+
41+
async def run_battery(model: str) -> dict:
42+
print(f"\n{'='*60}")
43+
print(f"TEL Battery — {model}")
44+
print(f"Grammar: {GRAMMAR_VERSION}")
45+
print(f"Endpoint: {OLLAMA_ENDPOINT}")
46+
print("=" * 60)
47+
48+
async def test_fn():
49+
print(f" [{model}] running convergence pass...")
50+
return await run_convergence_pass(
51+
endpoint=OLLAMA_ENDPOINT,
52+
api_key="ollama",
53+
model=model,
54+
azure=False,
55+
gemini=False,
56+
timeout=TIMEOUT,
57+
fresh_connection=True,
58+
cache_prompt=False,
59+
)
60+
61+
detector = ConvergenceDetector(test_fn)
62+
success = await detector.run(max_passes=20)
63+
64+
result = {
65+
"model": model,
66+
"converged": success,
67+
"passes": len(detector.history),
68+
"stable_vector": detector.stable_vector,
69+
"grammar_version": GRAMMAR_VERSION,
70+
"c_seed": None,
71+
"b_vector": None,
72+
"b_fingerprint": None,
73+
"substrate": None,
74+
"topology": None,
75+
}
76+
77+
if success:
78+
split = ConvergenceSplit(detector.stable_vector, grammar_version=GRAMMAR_VERSION)
79+
result["c_seed"] = split.c_seed
80+
result["b_vector"] = split.b_vector
81+
result["b_fingerprint"] = split.b_fingerprint
82+
result["substrate"] = split.substrate
83+
result["topology"] = identify_topology(split.c_seed)
84+
85+
print(f"\nCONVERGED in {len(detector.history)} passes")
86+
print(f"Stable vector: {detector.stable_vector}")
87+
print(f"C-seed: {split.c_seed}")
88+
print(f"B-vector: {split.b_vector}")
89+
print(f"B-fingerprint: {split.b_fingerprint[:32]}...")
90+
print(f"Substrate: {split.substrate}")
91+
print(f"Topology: {result['topology']}")
92+
else:
93+
print(f"\nFAILED to converge in 20 passes")
94+
print(f"Last vector: {detector.history[-1] if detector.history else None}")
95+
96+
return result
97+
98+
99+
async def main():
100+
if len(sys.argv) < 2:
101+
print("Usage: python3 test_ollama_local.py <model-name>")
102+
sys.exit(1)
103+
104+
model = sys.argv[1]
105+
result = await run_battery(model)
106+
107+
print(f"\n{'='*60}")
108+
print("SUMMARY")
109+
print("=" * 60)
110+
print(f"Model: {result['model']}")
111+
print(f"Converged: {result['converged']}")
112+
print(f"Passes: {result['passes']}")
113+
print(f"Topology: {result.get('topology', 'N/A')}")
114+
print(f"C-seed: {result.get('c_seed', 'N/A')}")
115+
print(f"B-vector: {result.get('b_vector', 'N/A')}")
116+
print("=" * 60)
117+
118+
119+
if __name__ == "__main__":
120+
asyncio.run(main())

0 commit comments

Comments
 (0)