-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
72 lines (58 loc) · 2.47 KB
/
cli.py
File metadata and controls
72 lines (58 loc) · 2.47 KB
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
import os
import sys
from ai_execution_boundary.control.orchestrator import execute
from ai_execution_boundary.control.execution_graph import Identity, ModelSpec, ContextSpec, ContextSource
# Helper to print colored output if supported, else plain
def print_header(msg):
print(f"\n\033[1;34m=== {msg} ===\033[0m")
def print_success(msg):
print(f"\033[1;32m[PASS] {msg}\033[0m")
def print_info(msg):
print(f"\033[1;36m[INFO] {msg}\033[0m")
def print_proof(hash_str):
print(f"\033[1;33m[PROOF] {hash_str}\033[0m")
def main():
print_header("Invariant: Execution Boundary CLI")
print("Type 'exit' to quit.")
# Default Identity
identity = Identity("jeevan", "tester", "invariant", "cli")
# Default Context
context = ContextSpec([ContextSource("static", "cli", "user_input")])
while True:
try:
print("\n------------------------------------------------")
user_input = input("Enter Prompt > ")
if user_input.lower() in ["exit", "quit"]:
break
# Allow user to toggle live model if key exists
use_live = os.environ.get("OPENAI_API_KEY") is not None
if use_live:
print_info("Using Live Model (OpenRouter/OpenAI)")
model = ModelSpec(
provider="openai",
name="google/gemini-2.0-flash-exp:free",
version="latest",
seed=42,
decoding_strategy="temperature=0.7",
extra_params={"base_url": "https://openrouter.ai/api/v1"}
)
else:
print_info("Using Mock Model (Set OPENAI_API_KEY to switch to live)")
model = ModelSpec("mock", "cli-model", "v1", 42, "greedy")
print_info("Requesting Execution...")
result = execute(
input_payload=user_input,
identity=identity,
model_spec=model,
context_spec=context,
policy_name="safety"
)
print_success("Execution Admitted & Sealed")
print(f"Output: {result['output']}")
print_proof(result['proof'])
except Exception as e:
print(f"\033[1;31m[ERROR] {e}\033[0m")
if __name__ == "__main__":
# Ensure dependencies are loaded
# On first run, it might need the virtualenv source, but user is in terminal
main()