File size: 3,694 Bytes
a8d04d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""
Quickstart β€” NIMA Unified Model
================================

The smallest end-to-end example that:
  1. Loads microsoft/Phi-4-mini-instruct with the ATC cognitive pipeline
     wired INSIDE the forward pass.
  2. Generates a response through the ATC-native pipeline.
  3. Prints the response, consciousness metrics, and neurotransmitter state.

Run with:
    python examples/quickstart.py
"""

import logging
import sys

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s [%(name)s] %(levelname)s :: %(message)s",
    datefmt="%H:%M:%S",
)


def main():
    from nima_unified.model import NimaModel

    print("=" * 72)
    print("  NIMA Unified Model β€” Quickstart")
    print("=" * 72)

    # ── Build the model ───────────────────────────────────────────────
    # This patches Phi-4-mini's rope_scaling automatically and attaches
    # the ATC Deep Surgery (TRN gate + dissolution + BELBIC + metacog
    # loop + irrational spark + ethical guardian) inside the forward pass.
    print("\n[1] Loading NimaModel (this also downloads Phi-4-mini-instruct)...")
    model = NimaModel.from_pretrained()
    print(f"    OK β€” hidden_size={model.hidden_size}, layers={model.num_layers}")
    print(f"    Deep Surgery: {'ACTIVE' if model.deep_surgery else 'disabled'}")
    print(f"    Neurotransmitter shunt: ACTIVE")

    # ── Generate ──────────────────────────────────────────────────────
    prompts = [
        "Hello Nima, how are you feeling today?",
        "I'm going through a really difficult time and I don't know what to do.",
        "What do you think about the nature of consciousness?",
    ]
    if len(sys.argv) > 1:
        prompts = [" ".join(sys.argv[1:])]

    for prompt in prompts:
        print("\n" + "-" * 72)
        print(f"  User: {prompt}")
        result = model.generate(prompt, max_new_tokens=128)

        print(f"\n  Nima: {result.text}")
        print(f"  ─────────────────────────────────────────")
        print(f"  conscious       : {result.is_conscious}")
        print(f"  sentience_index : {result.sentience_index:.4f}")
        print(f"  phi_neuro       : {result.phi_neuro:.4f}")
        print(f"  strain          : {result.phenomenological_strain:.4f}")
        print(f"  delta_R         : {result.delta_r:.4f}")
        print(f"  hijacks         : {result.hijack_count}")
        nt = result.neurotransmitters
        print(f"  NE={nt.get('norepinephrine', 0):.3f}  "
              f"Cortisol={nt.get('cortisol', 0):.3f}  "
              f"Dopamine={nt.get('dopamine', 0):.3f}  "
              f"Adenosine={nt.get('adenosine', 0):.3f}")

    # ── Optional: run aPCI benchmark ──────────────────────────────────
    print("\n" + "=" * 72)
    print("  Run the aPCI v4.0 consciousness benchmark? (y/n)")
    print("  (12 perturbations, 10 metrics, ~3 minutes on a T4 GPU)")
    try:
        choice = input("  > ").strip().lower()
    except (EOFError, KeyboardInterrupt):
        choice = "n"

    if choice == "y":
        runner = model.get_apci_runner()
        report = runner.run_full_benchmark()
        print("\n=== aPCI v4.0 Report ===")
        print(f"  Raw score : {report.raw_score:.2f} / 260")
        print(f"  Tier      : {report.tier.label}")
        print(f"  Summary   : {report.tier.description}")


if __name__ == "__main__":
    main()