-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
55 lines (39 loc) · 1.76 KB
/
main.py
File metadata and controls
55 lines (39 loc) · 1.76 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
from modules.argParser import parse_arguments
from modules.template.template import create_prompt
from modules.chat import send
from modules.executor import execute_command
from modules.security import is_command_approved
from modules.extractor import extract_command
from modules.pause import maybePause
from config import COMMAND_DELIMITER as delimiter
args = None
def prompting_loop(message, depth=0):
depth = depth + 1
if depth > 1:
print("message: ", message)
response = send(message)
print("response: ", response)
command = extract_command(response)
if command == None:
message = f"Message from AI-exector: Your message did not include a {delimiter}command{delimiter}. Please remember that I only process commands and they must be formatted properly ({delimiter}command{delimiter}). Thank You!"
prompting_loop(message, depth)
# if is_command_approved(command):
if True:
maybePause(command, args.pause)
stdout, stderr = execute_command(command)
if stderr == "":
nextMessage = f"Message from AI-exector: Your command ({command}) was executed successfully. Here is the output: '{stdout}'"
else:
nextMessage = f"Message from AI-exector: Your command ({command}) was executed but there was an error. Here is the output: '{stdout}' and here is the error: '{stderr}'"
# output is treated as a response from the user
if depth < 10:
prompting_loop(nextMessage, depth)
else:
print("depth met")
return
else:
print(f"Command {response} is not approved for execution.")
if __name__ == "__main__":
args = parse_arguments()
prompt = create_prompt(args.desire, args.system)
prompting_loop(prompt)