-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_ai_bridge.py
More file actions
103 lines (84 loc) · 3.8 KB
/
Copy pathsetup_ai_bridge.py
File metadata and controls
103 lines (84 loc) · 3.8 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
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
import os
import subprocess
PROJECT_DIR = os.path.expanduser("~/str8zero_engine")
def run_cmd(command):
print(f" [+] Executing: {command}")
result = subprocess.run(command, shell=True, cwd=PROJECT_DIR, text=True)
if result.returncode != 0:
print(f" [!] Warning or error on: {command}")
def create_full_workspace():
print(f"[Str8Zero AI Bridge Bootstrapper] Initializing workspace at: {PROJECT_DIR}")
dirs = [
PROJECT_DIR,
os.path.join(PROJECT_DIR, "app"),
os.path.join(PROJECT_DIR, "config")
]
for d in dirs:
os.makedirs(d, exist_ok=True)
print(f" [+] Verified directory: {d}")
# 1. Write Local-to-Cloud Sync Engine (`sync_cloud.py`)
sync_py_code = '''import os
import subprocess
PROJECT_DIR = os.path.expanduser("~/str8zero_engine")
def run_cmd(command):
print(f" [+] Executing: {command}")
result = subprocess.run(command, shell=True, cwd=PROJECT_DIR, text=True)
if result.returncode != 0:
print(f" [!] Error executing {command}")
exit(1)
def sync_repository():
print("[Str8Zero Sync] Initiating local-to-cloud synchronization...")
os.chdir(PROJECT_DIR)
run_cmd("git status")
run_cmd("git add .")
run_cmd('git commit -m "Field terminal sync from A1286 client deck" || echo "No changes to commit"')
run_cmd("git push origin main || echo 'Check remote configuration or branch name'")
print("[Str8Zero Sync] Synchronization sequence complete!")
if __name__ == "__main__":
sync_repository()
'''
with open(os.path.join(PROJECT_DIR, "sync_cloud.py"), "w", encoding="utf-8") as f:
f.write(sync_py_code)
print(" [✓] Created sync_cloud.py")
# 2. Write The AI Tooling & LLM Bridge (`app/ai_bridge.py`)
ai_bridge_code = '''import requests
import json
class Str8ZeroAIBridge:
def __init__(self, endpoint="http://localhost:11434/api/generate", model="llama3.2"):
self.endpoint = endpoint
self.model = model
def query_engine(self, prompt: str) -> str:
payload = {
"model": self.model,
"prompt": prompt,
"stream": False
}
headers = {"Content-Type": "application/json"}
try:
response = requests.post(self.endpoint, data=json.dumps(payload), headers=headers, timeout=30)
if response.status_code == 200:
return response.json().get("response", "No response field found.")
else:
return f"Error: Received status code {response.status_code}"
except Exception as e:
return f"Connection error to AI runtime: {str(e)}"
if __name__ == "__main__":
bridge = Str8ZeroAIBridge()
print("[AI Bridge] Initialized model connector for:", bridge.model)
'''
with open(os.path.join(PROJECT_DIR, "app", "ai_bridge.py"), "w", encoding="utf-8") as f:
f.write(ai_bridge_code)
print(" [✓] Created app/ai_bridge.py")
# 3. Write Architecture Manifest (`README.md`)
readme_content = '''# Str8Zero // Hybrid Cloud Field Terminal & AI Bridge
A zero-cost, cloud-bridged development and intelligence pipeline designed for legacy client hardware (MacBook Pro A1286 / macOS Sierra field terminal tethered via iPhone USB).
## Core Components:
* **Sync Engine (`sync_cloud.py`):** Automates staging, committing, and pushing local field terminal state to cloud runtimes.
* **AI Tooling Bridge (`app/ai_bridge.py`):** Interfaces lightweight clients with heavy LLM execution runtimes (Ollama / Codespaces).
'''
with open(os.path.join(PROJECT_DIR, "README.md"), "w", encoding="utf-8") as f:
f.write(readme_content)
print(" [✓] Created README.md")
print("\n[Str8Zero Bootstrapper] All hybrid AI bridge assets successfully deployed and locked into place!")
if __name__ == "__main__":
create_full_workspace()