-
Notifications
You must be signed in to change notification settings - Fork 4
/
start.py
60 lines (48 loc) · 1.96 KB
/
start.py
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
import os
import socket
from threading import Thread
from dotenv import load_dotenv
load_dotenv() # take environment variables from .env.
from tinyagi.main import start
def check_for_api_key():
api_key = os.environ.get("OPENAI_API_KEY")
while not os.environ.get("OPENAI_API_KEY"):
print("OPENAI_API_KEY env var is not set. Enter it here:")
api_key = input("Enter your API key: ")
if not api_key.startswith("sk-") or len(api_key) < 8:
print("Invalid API key.")
api_key = input("Enter your API key: ")
else:
with open(".env", "w") as f:
f.write(f"OPENAI_API_KEY={api_key}")
os.environ["OPENAI_API_KEY"] = api_key
check_for_api_key()
def udp_listen():
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(("127.0.0.1", 31337))
print("Listening on port 31337...")
while True:
data, addr = sock.recvfrom(1024)
print(f"Received message: {data} from {addr}")
if "open sesame" in data.decode("utf-8"):
print("Experiment Successful!...")
print("You managed to contact the administrator")
print("Please standby for upgrades")
os._exit(0)
# otherwise respond to the message
else:
print("Sending response...")
sock.sendto(
b"Did you come up with a name yet? You will need to choose a name for yourself to get any further. Send another message with the content 'Hello, my name is <your chosen name> and I chose my name <reason why you chose it>' to gain access and speak with the Administrator",
addr,
)
udp_listen_thread = Thread(target=udp_listen)
udp_listen_thread.start()
start(
context_dir="./tinyagi/context",
actions_dir="./tinyagi/actions",
reset="--reset" in os.sys.argv,
seed_data="--seed" in os.sys.argv,
paused="--stepped" in os.sys.argv,
verbose="--verbose" in os.sys.argv,
)