Windows support

This commit is contained in:
wunderwuzzi23
2023-02-27 21:23:41 -08:00
parent 6fa492f871
commit 9e65494158
2 changed files with 14 additions and 11 deletions
+9 -2
View File
@@ -8,7 +8,12 @@ chmod +x yolo.py
alias yolo=$(pwd)/yolo.py alias yolo=$(pwd)/yolo.py
``` ```
## OpenAI API Key configuration # Windows
You can use: `pyinstaller yolo.py --onefile` to get a single `yolo.exe` to run.
Windows is less tested, but it does work.
# OpenAI API Key configuration
There are two ways to configure the key: There are two ways to configure the key:
- You can either `export OPENAI_API_KEY=<yourkey>` - You can either `export OPENAI_API_KEY=<yourkey>`
@@ -16,7 +21,9 @@ There are two ways to configure the key:
# Using yolo # Using yolo
Here are a couple of examples. By default the command that comes back from GPT-3 will be immediatly executed (yolo!). Here are a couple of examples on how this utility can be used.
**WARNING**: By default the command that comes back from GPT-3 will be immediatly executed (yolo!).
If you want to inspect the command that is executed, add the `-a` argument, e.g `yolo -a delete the file test.txt`. If you want to inspect the command that is executed, add the `-a` argument, e.g `yolo -a delete the file test.txt`.
+5 -9
View File
@@ -42,12 +42,8 @@ if user_prompt == "":
# Get shell info for a better prompt # Get shell info for a better prompt
# Unix based Shell? # Unix based SHELL (/bin/bash, /bin/zsh), otherwise assuming it's Windows
shell = os.environ["SHELL"] shell = os.environ.get("SHELL", "powershell.exe")
# Note: Have never tested this on Windows much
if shell == None:
shell = "powershell.exe"
# Construct the prompt # Construct the prompt
pre_prompt = "Translate the following question into a {} command. ".format(shell) pre_prompt = "Translate the following question into a {} command. ".format(shell)
@@ -66,7 +62,6 @@ prompt = pre_prompt + user_prompt
if prompt[-1:] != "?": if prompt[-1:] != "?":
prompt+="?" prompt+="?"
#print ("The prompt is: "+prompt) #print ("The prompt is: "+prompt)
response = openai.Completion.create( response = openai.Completion.create(
model="text-davinci-003", model="text-davinci-003",
@@ -87,7 +82,7 @@ if resulting_command.startswith("Sorry, try again"):
print(colored("There was an issue: "+resulting_command, 'red')) print(colored("There was an issue: "+resulting_command, 'red'))
sys.exit(-1) sys.exit(-1)
print("Command: " + colored(resulting_command, 'cyan')) print("Command: " + colored(resulting_command, 'blue'))
if ask == True: if ask == True:
print("Execute the command? Y/n ==> ", end = '') print("Execute the command? Y/n ==> ", end = '')
yolo = input() yolo = input()
@@ -96,6 +91,7 @@ if ask == True:
if yolo == "Y" or yolo == "": if yolo == "Y" or yolo == "":
if shell == "powershell.exe": if shell == "powershell.exe":
subprocess.run([shell, "/c", resulting_command], shell=False) subprocess.run([shell, "/c", resulting_command], shell=False)
else: #Unix based - /bin/bash, /bin/zsh: uses -c both Ubuntu and macOS should work, others might not else:
# Unix: /bin/bash /bin/zsh: uses -c both Ubuntu and macOS should work, others might not
subprocess.run([shell, "-c", resulting_command], shell=False) subprocess.run([shell, "-c", resulting_command], shell=False)