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
```
## 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:
- You can either `export OPENAI_API_KEY=<yourkey>`
@@ -16,7 +21,9 @@ There are two ways to configure the key:
# 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`.
+5 -9
View File
@@ -42,12 +42,8 @@ if user_prompt == "":
# Get shell info for a better prompt
# Unix based Shell?
shell = os.environ["SHELL"]
# Note: Have never tested this on Windows much
if shell == None:
shell = "powershell.exe"
# Unix based SHELL (/bin/bash, /bin/zsh), otherwise assuming it's Windows
shell = os.environ.get("SHELL", "powershell.exe")
# Construct the prompt
pre_prompt = "Translate the following question into a {} command. ".format(shell)
@@ -66,7 +62,6 @@ prompt = pre_prompt + user_prompt
if prompt[-1:] != "?":
prompt+="?"
#print ("The prompt is: "+prompt)
response = openai.Completion.create(
model="text-davinci-003",
@@ -87,7 +82,7 @@ if resulting_command.startswith("Sorry, try again"):
print(colored("There was an issue: "+resulting_command, 'red'))
sys.exit(-1)
print("Command: " + colored(resulting_command, 'cyan'))
print("Command: " + colored(resulting_command, 'blue'))
if ask == True:
print("Execute the command? Y/n ==> ", end = '')
yolo = input()
@@ -96,6 +91,7 @@ if ask == True:
if yolo == "Y" or yolo == "":
if shell == "powershell.exe":
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)