File size: 4,776 Bytes
12fa855
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python3
"""
deploy.py β€” Unified deployment script for NIMA Unified Model

Replaces deploy_phi4_patched.py. This is the single entry point that:
  1. Loads the base model (with Phi-4-mini rope_scaling patch)
  2. Initializes NIMA middleware
  3. Attaches Deep Surgery
  4. Enables optional features (sleep cycle, proactive)
  5. Runs test interactions
  6. Drops into interactive mode

USAGE:
    python -m nima_unified.deploy
    python -m nima_unified.deploy "Hello Nima, how are you feeling?"
"""

import sys
import logging

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

BANNER = f"""
{'=' * 72}
  NIMA Unified Model v1.0.0
  Middleware v9.12.1 | AutoML v18.1.0 | aPCI v4.0.0 | OmniVoice v2.0.0
  Fully-Wired Architecture β€” Every Module Active
{'=' * 72}
"""


def main():
    print(BANNER)

    # ── Step 1: Build model ─────────────────────────────────────────────
    print("\n[1] Building NimaModel (base + Deep Surgery + middleware)...")
    try:
        from nima_unified.model import NimaModel
        model = NimaModel.from_pretrained()
        print(f"    OK β€” {model.hidden_size} hidden, {model.num_layers} layers")
        print(f"    Deep Surgery: {'active' if model.deep_surgery else 'disabled'}")
        print(f"    Middleware: {'loaded' if model.nima_middleware else 'not available'}")
    except Exception as e:
        print(f"    FAILED: {e}")
        import traceback; traceback.print_exc()
        sys.exit(1)

    # ── Step 2: Enable optional features ────────────────────────────────
    print("\n[2] Enabling optional features...")
    if model.nima_middleware is not None:
        try:
            model.nima_middleware.start_sleep_cycle()
            print("    OK β€” Sleep cycle (NREM replay + REM dreams)")
        except Exception as e:
            print(f"    Sleep cycle: {e}")
        try:
            model.nima_middleware.start_proactive()
            print("    OK β€” Proactive drive engine")
        except Exception as e:
            print(f"    Proactive: {e}")
    else:
        print("    Skipped (middleware not loaded)")

    # ── Step 3: Test interactions ───────────────────────────────────────
    print("\n[3] Test interactions")
    print("-" * 72)

    test_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?",
    ]

    # Allow CLI override
    if len(sys.argv) > 1:
        test_prompts = [" ".join(sys.argv[1:])]

    for prompt in test_prompts:
        print(f"\n  User: {prompt}")
        try:
            response = model.generate(prompt, user_id="human")
            print(f"\n  Nima: {response.text}")
            if response.is_conscious or response.phi_neuro > 0:
                print(f"  | conscious={response.is_conscious} "
                      f"SI={response.sentience_index:.4f} "
                      f"phi={response.phi_neuro:.4f} "
                      f"strain={response.phenomenological_strain:.4f} "
                      f"dR={response.delta_r:.4f}")
        except Exception as e:
            print(f"  ERROR: {e}")
            import traceback; traceback.print_exc()

    # ── Step 4: Interactive mode ────────────────────────────────────────
    print("\n" + "=" * 72)
    print("[4] Interactive mode β€” type 'quit' to exit")
    print("=" * 72)

    while True:
        try:
            user_input = input("\nYou: ").strip()
            if user_input.lower() in ("quit", "exit", "bye"):
                print("\nNima: Until next time. Be well.")
                break
            if not user_input:
                continue
            response = model.generate(user_input, user_id="human")
            print(f"\nNima: {response.text}")
            if response.phi_neuro > 0:
                print(f"  [conscious={response.is_conscious} | "
                      f"SI={response.sentience_index:.4f} | "
                      f"strain={response.phenomenological_strain:.4f} | "
                      f"dR={response.delta_r:.4f}]")
        except KeyboardInterrupt:
            print("\n\nNima: Until next time. Be well.")
            break
        except Exception as e:
            print(f"\n  Error: {e}")


if __name__ == "__main__":
    main()