-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
47 lines (29 loc) · 920 Bytes
/
main.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
from openai import OpenAI
import os
import subprocess
client = OpenAI(api_key='')
messages = [
{"role": "system", "content": "You are a Terminal Assistant and your job is to output commands according to my query. My system is garuda linux and the shell is fish. You just have to output the command and not anything else"}
]
def main():
while True:
query = input("Query: ")
if query == "quit" or query == "exit":
break
query = query + "output commands only"
command = getCommand(query)
x = input('y or n: ')
if x == 'y':
subprocess.run(['fish', '-c', command])
def getCommand(query):
message = query
if message:
messages.append(
{"role": "user", "content": message},
)
chat = client.chat.completions.create(model="gpt-3.5-turbo", messages=messages)
reply = chat.choices[0].message.content
print(f"Command: {reply}")
return reply
if __name__ == "__main__":
main()