-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtermie
executable file
·36 lines (24 loc) · 870 Bytes
/
termie
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
#!/usr/bin/env python3
import sys
import os
import openai
PRE_PROMPT = 'The response should be a standalone shell command. Ensure the command is just one string and nothing else.'
def main():
openai.api_key = os.environ.get('OPENAI_API_KEY')
input_argument = sys.argv[1:][0]
response = openai.ChatCompletion.create(
model = 'gpt-3.5-turbo',
messages = [
{'role': 'system', 'content': PRE_PROMPT},
{'role': 'user', 'content': input_argument}
]
)
shell_command = response['choices'][0]['message']['content']
print(f"Shell command: {shell_command}")
confirm = input('Would you like to run this command? ([Y]/n) ')
if not confirm or confirm.lower() == 'y':
os.system(shell_command)
else:
print('Command execution aborted.')
if __name__ == "__main__":
main()