|
| 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