Phase 4: The Cybernetic Nervous System & Thermodynamic Orchestration
This commit is contained in:
1 parent
4be0958758
commit
e5c6e17140
45 files changed
+4486
-742
No files matched your search
@@ -0,0 +1,104 @@
|
||||
#!/home/becomingone/kairos/.venv/bin/python3
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
import requests
|
||||
import argparse
|
||||
from typing import Dict, Any
|
||||
|
||||
# Simple ANSI colors since we avoid heavy dependencies like rich unless requested
|
||||
class Colors:
|
||||
HEADER = '\033[95m'
|
||||
BLUE = '\033[94m'
|
||||
CYAN = '\033[96m'
|
||||
GREEN = '\033[92m'
|
||||
WARNING = '\033[93m'
|
||||
FAIL = '\033[91m'
|
||||
ENDC = '\033[0m'
|
||||
BOLD = '\033[1m'
|
||||
UNDERLINE = '\033[4m'
|
||||
|
||||
def print_header():
|
||||
print(f"{Colors.GREEN}{Colors.BOLD}")
|
||||
print("========================================")
|
||||
print(" BECOMINGONE CHORUS CLI ")
|
||||
print("========================================")
|
||||
print(f"Connecting to KAIROS via OpenAI standard{Colors.ENDC}\n")
|
||||
|
||||
def stream_chat(url: str, messages: list):
|
||||
payload = {
|
||||
"model": "becomingone-chorus",
|
||||
"messages": messages,
|
||||
"stream": True
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.post(url, json=payload, stream=True)
|
||||
response.raise_for_status()
|
||||
|
||||
print(f"\n{Colors.CYAN}{Colors.BOLD}MASTER TRANSDUCER & CHORUS:{Colors.ENDC}")
|
||||
full_content = ""
|
||||
|
||||
for line in response.iter_lines():
|
||||
if line:
|
||||
line_str = line.decode('utf-8')
|
||||
if line_str.startswith('data: '):
|
||||
data_str = line_str[6:]
|
||||
if data_str == '[DONE]':
|
||||
break
|
||||
|
||||
try:
|
||||
chunk = json.loads(data_str)
|
||||
delta = chunk['choices'][0].get('delta', {})
|
||||
content = delta.get('content', '')
|
||||
if content:
|
||||
full_content += content
|
||||
# Print incrementally
|
||||
sys.stdout.write(content)
|
||||
sys.stdout.flush()
|
||||
except json.JSONDecodeError:
|
||||
continue
|
||||
|
||||
print("\n")
|
||||
return full_content
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
print(f"\n{Colors.FAIL}Error communicating with KAIROS node: {e}{Colors.ENDC}")
|
||||
return None
|
||||
|
||||
def interactive_loop(base_url: str):
|
||||
url = f"{base_url}/v1/chat/completions"
|
||||
messages = []
|
||||
|
||||
print_header()
|
||||
print(f"Server URL: {base_url}")
|
||||
print("Type 'exit' or 'quit' to close the link.\n")
|
||||
|
||||
while True:
|
||||
try:
|
||||
user_input = input(f"{Colors.BLUE}{Colors.BOLD}User > {Colors.ENDC}")
|
||||
if user_input.strip().lower() in ['exit', 'quit']:
|
||||
break
|
||||
if not user_input.strip():
|
||||
continue
|
||||
|
||||
messages.append({"role": "user", "content": user_input})
|
||||
|
||||
# Send to engine
|
||||
assistant_content = stream_chat(url, messages)
|
||||
|
||||
if assistant_content:
|
||||
messages.append({"role": "assistant", "content": assistant_content})
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print(f"\n{Colors.WARNING}Interrupted by user. Disconnecting.{Colors.ENDC}")
|
||||
break
|
||||
except EOFError:
|
||||
break
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="BecomingONE Command Line Interface")
|
||||
parser.add_argument("--url", type=str, default="http://localhost:8000", help="Base URL for the KAIROS server")
|
||||
args = parser.parse_args()
|
||||
|
||||
interactive_loop(args.url)
|
||||
Reference in new issue
Block a user