From f5280a1b1b7cce35156c2084b887ab543c22538a Mon Sep 17 00:00:00 2001 From: KAuser2094 Date: Mon, 6 Mar 2023 10:11:37 +0000 Subject: [PATCH 1/7] First Windows Version --- install.sh | 16 ++++++---------- yolo.bat | 3 +++ yolo.py | 9 +++++---- 3 files changed, 14 insertions(+), 14 deletions(-) create mode 100644 yolo.bat diff --git a/install.sh b/install.sh index 73ac811..2db7871 100644 --- a/install.sh +++ b/install.sh @@ -1,16 +1,12 @@ -# Installs yolo in the user's home directory +# Installs yolo in the user's CMD directory ( change $CMD to desired file path ) -TARGET_DIR=~/yolo-ai-cmdbot +TARGET_DIR=$CMD TARGET_FULLPATH=$TARGET_DIR/yolo.py mkdir -p $TARGET_DIR -cp yolo.py prompt.txt $TARGET_DIR +cp yolo.py $TARGET_DIR +cp prompt.txt $TARGET_DIR/yolo_prompt.txt #changed this so it doesnt conflict with possible future prompts chmod +x $TARGET_FULLPATH -# Creates two aliases for use -alias yolo=$TARGET_FULLPATH -alias computer=$TARGET_FULLPATH - -# Add the aliases to the logon scripts -echo "alias yolo=$TARGET_FULLPATH" >> ~/.bash_aliases -echo "alias computer=$TARGET_FULLPATH" >> ~/.bash_aliases +# Adds batch file to System32 so you can call it in powershell +cp yolo.bat C:/Windows/System32 \ No newline at end of file diff --git a/yolo.bat b/yolo.bat new file mode 100644 index 0000000..8eac22f --- /dev/null +++ b/yolo.bat @@ -0,0 +1,3 @@ +@echo off +set /P "prompt=Enter Prompt: " +python.exe C:\Users\kause\Downloads\Commands\yolo.py %prompt% diff --git a/yolo.py b/yolo.py index 0333f45..226ec6e 100755 --- a/yolo.py +++ b/yolo.py @@ -12,6 +12,8 @@ import subprocess from termcolor import colored from colorama import init +import dotenv + # Check if the user globally disabled the safety switch def get_yolo_safety_switch_config(): @@ -32,7 +34,7 @@ def get_full_prompt(user_prompt, shell): prompt_path = os.path.dirname(yolo_path) ## Load the prompt and prep it - prompt_file = os.path.join(prompt_path, "prompt.txt") + prompt_file = os.path.join(prompt_path, "yolo_prompt.txt") pre_prompt = open(prompt_file,"r").read() pre_prompt = pre_prompt.replace("{shell}", shell) pre_prompt = pre_prompt.replace("{os}", get_os_friendly_name()) @@ -78,10 +80,9 @@ if __name__ == "__main__": ask_flag = False # safety switch -a command line argument yolo = "" # user's answer to safety switch (-a) question y/n - # Two options for the user to specify they openai api key - home_path = os.path.expanduser("~") + # Presumes the folder yolo.py is copied to has a .env + dotenv.load_dotenv(".env") openai.api_key = os.getenv("OPENAI_API_KEY") - openai.api_key_path = os.path.join(home_path,".openai.apikey") # Parse arguments and make sure we have at least a single word if len(sys.argv) < 2: From 8be32f90da65056fd6bd1339f887957919237a4e Mon Sep 17 00:00:00 2001 From: KAuser2094 Date: Mon, 6 Mar 2023 10:57:47 +0000 Subject: [PATCH 2/7] Starting better version (And not whatever hacky version I first though of) --- install.sh | 31 +++++++++++++++++++++++++------ yolo.bat | 6 +++++- yolo.py | 11 +++++------ 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/install.sh b/install.sh index 2db7871..c98938f 100644 --- a/install.sh +++ b/install.sh @@ -1,12 +1,31 @@ -# Installs yolo in the user's CMD directory ( change $CMD to desired file path ) +# Installs yolo in the user's home directory -TARGET_DIR=$CMD +TARGET_DIR=~/yolo-ai-cmdbot TARGET_FULLPATH=$TARGET_DIR/yolo.py mkdir -p $TARGET_DIR -cp yolo.py $TARGET_DIR -cp prompt.txt $TARGET_DIR/yolo_prompt.txt #changed this so it doesnt conflict with possible future prompts +cp yolo.py prompt.txt $TARGET_DIR chmod +x $TARGET_FULLPATH -# Adds batch file to System32 so you can call it in powershell -cp yolo.bat C:/Windows/System32 \ No newline at end of file +#Linux/Mac + +# Creates two aliases for use +alias yolo=$TARGET_FULLPATH +alias computer=$TARGET_FULLPATH + +# Add the aliases to the logon scripts +echo "alias yolo=$TARGET_FULLPATH" >> ~/.bash_aliases +echo "alias computer=$TARGET_FULLPATH" >> ~/.bash_aliases + +# Windows +# Copy yolo.bat to System32 or : + +# (This doesn't work, havent figured it out) + +# Creates two aliases for use +alias yolo=$TARGET_FULLPATH +alias computer=$TARGET_FULLPATH + +# Add the aliases to the logon scripts +echo "alias yolo=$TARGET_FULLPATH" >> ~/.bash_aliases +echo "alias computer=$TARGET_FULLPATH" >> ~/.bash_aliases \ No newline at end of file diff --git a/yolo.bat b/yolo.bat index 8eac22f..13fdc30 100644 --- a/yolo.bat +++ b/yolo.bat @@ -1,3 +1,7 @@ @echo off + +REM Work around to not have to type in python.exe yolo.py every time. +REM Put in C:/Windows/System32 to allow command to work anywhere + set /P "prompt=Enter Prompt: " -python.exe C:\Users\kause\Downloads\Commands\yolo.py %prompt% +python.exe ~/yolo-ai-cmdbot/yolo.py %prompt% diff --git a/yolo.py b/yolo.py index 226ec6e..b5664bd 100755 --- a/yolo.py +++ b/yolo.py @@ -12,8 +12,6 @@ import subprocess from termcolor import colored from colorama import init -import dotenv - # Check if the user globally disabled the safety switch def get_yolo_safety_switch_config(): @@ -34,7 +32,7 @@ def get_full_prompt(user_prompt, shell): prompt_path = os.path.dirname(yolo_path) ## Load the prompt and prep it - prompt_file = os.path.join(prompt_path, "yolo_prompt.txt") + prompt_file = os.path.join(prompt_path, "prompt.txt") pre_prompt = open(prompt_file,"r").read() pre_prompt = pre_prompt.replace("{shell}", shell) pre_prompt = pre_prompt.replace("{os}", get_os_friendly_name()) @@ -80,9 +78,10 @@ if __name__ == "__main__": ask_flag = False # safety switch -a command line argument yolo = "" # user's answer to safety switch (-a) question y/n - # Presumes the folder yolo.py is copied to has a .env - dotenv.load_dotenv(".env") + # Two options for the user to specify they openai api key + home_path = os.path.expanduser("~") openai.api_key = os.getenv("OPENAI_API_KEY") + openai.api_key_path = os.path.join(home_path,".openai.apikey") # Parse arguments and make sure we have at least a single word if len(sys.argv) < 2: @@ -154,4 +153,4 @@ if yolo == "Y" or yolo == "": subprocess.run([shell, "/c", res_command], shell=False) else: # Unix: /bin/bash /bin/zsh: uses -c both Ubuntu and macOS should work, others might not - subprocess.run([shell, "-c", res_command], shell=False) \ No newline at end of file + subprocess.run([shell, "-c", res_command], shell=False) From ce3ec3359eca60cff4413c96f3c1fa73e2260e6e Mon Sep 17 00:00:00 2001 From: KAuser2094 Date: Mon, 6 Mar 2023 12:32:22 +0000 Subject: [PATCH 3/7] First "proper" version --- install.sh | 13 +++++++------ yolo.bat | 3 ++- yolo.py | 10 +++++++--- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/install.sh b/install.sh index c98938f..ea61ddf 100644 --- a/install.sh +++ b/install.sh @@ -18,14 +18,15 @@ echo "alias yolo=$TARGET_FULLPATH" >> ~/.bash_aliases echo "alias computer=$TARGET_FULLPATH" >> ~/.bash_aliases # Windows -# Copy yolo.bat to System32 or : +# Copy yolo.bat to System32 or Home Directory : +cp yolo.bat ~ + # (This doesn't work, havent figured it out) - # Creates two aliases for use -alias yolo=$TARGET_FULLPATH -alias computer=$TARGET_FULLPATH +#alias yolo=$TARGET_FULLPATH +#alias computer=$TARGET_FULLPATH # Add the aliases to the logon scripts -echo "alias yolo=$TARGET_FULLPATH" >> ~/.bash_aliases -echo "alias computer=$TARGET_FULLPATH" >> ~/.bash_aliases \ No newline at end of file +#echo "alias yolo=$TARGET_FULLPATH" >> ~/.bash_aliases +#echo "alias computer=$TARGET_FULLPATH" >> ~/.bash_aliases \ No newline at end of file diff --git a/yolo.bat b/yolo.bat index 13fdc30..f68cd91 100644 --- a/yolo.bat +++ b/yolo.bat @@ -4,4 +4,5 @@ REM Work around to not have to type in python.exe yolo.py every time. REM Put in C:/Windows/System32 to allow command to work anywhere set /P "prompt=Enter Prompt: " -python.exe ~/yolo-ai-cmdbot/yolo.py %prompt% +cd ~ +python.exe yolo-ai-cmdbot/yolo.py %prompt% \ No newline at end of file diff --git a/yolo.py b/yolo.py index b5664bd..78e1775 100755 --- a/yolo.py +++ b/yolo.py @@ -12,6 +12,8 @@ import subprocess from termcolor import colored from colorama import init +import dotenv + # Check if the user globally disabled the safety switch def get_yolo_safety_switch_config(): @@ -78,10 +80,12 @@ if __name__ == "__main__": ask_flag = False # safety switch -a command line argument yolo = "" # user's answer to safety switch (-a) question y/n - # Two options for the user to specify they openai api key - home_path = os.path.expanduser("~") - openai.api_key = os.getenv("OPENAI_API_KEY") + + # Two options for the user to specify they openai api key. Windows: Comment out the one you are not using (Causes extra line to appear) + home_path = os.path.expanduser("~") openai.api_key_path = os.path.join(home_path,".openai.apikey") + dotenv.load_dotenv() + openai.api_key = os.getenv("OPENAI_API_KEY") # Parse arguments and make sure we have at least a single word if len(sys.argv) < 2: From 4f08e7cc0e9bc7e1bd7f4d74f9b7f5aaf2cf95ea Mon Sep 17 00:00:00 2001 From: KAuser2094 Date: Mon, 6 Mar 2023 12:42:42 +0000 Subject: [PATCH 4/7] Better bat file and remove redundant allias --- install.sh | 10 ---------- yolo.bat | 4 +--- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/install.sh b/install.sh index ea61ddf..f46023e 100644 --- a/install.sh +++ b/install.sh @@ -20,13 +20,3 @@ echo "alias computer=$TARGET_FULLPATH" >> ~/.bash_aliases # Windows # Copy yolo.bat to System32 or Home Directory : cp yolo.bat ~ - - -# (This doesn't work, havent figured it out) -# Creates two aliases for use -#alias yolo=$TARGET_FULLPATH -#alias computer=$TARGET_FULLPATH - -# Add the aliases to the logon scripts -#echo "alias yolo=$TARGET_FULLPATH" >> ~/.bash_aliases -#echo "alias computer=$TARGET_FULLPATH" >> ~/.bash_aliases \ No newline at end of file diff --git a/yolo.bat b/yolo.bat index f68cd91..cb25983 100644 --- a/yolo.bat +++ b/yolo.bat @@ -3,6 +3,4 @@ REM Work around to not have to type in python.exe yolo.py every time. REM Put in C:/Windows/System32 to allow command to work anywhere -set /P "prompt=Enter Prompt: " -cd ~ -python.exe yolo-ai-cmdbot/yolo.py %prompt% \ No newline at end of file +python.exe yolo-ai-cmdbot/yolo.py %1 \ No newline at end of file From 9805412c55b7422be0a2b77c9563642b55023d9d Mon Sep 17 00:00:00 2001 From: KAuser2094 Date: Mon, 6 Mar 2023 12:48:13 +0000 Subject: [PATCH 5/7] Fix to bat file, accept all words not one --- yolo.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yolo.bat b/yolo.bat index cb25983..b958c12 100644 --- a/yolo.bat +++ b/yolo.bat @@ -3,4 +3,4 @@ REM Work around to not have to type in python.exe yolo.py every time. REM Put in C:/Windows/System32 to allow command to work anywhere -python.exe yolo-ai-cmdbot/yolo.py %1 \ No newline at end of file +python.exe yolo-ai-cmdbot/yolo.py %* \ No newline at end of file From e75925c3f2c0d5cfedc38c97c3a211135b9686a6 Mon Sep 17 00:00:00 2001 From: KAuser2094 Date: Mon, 6 Mar 2023 16:08:28 +0000 Subject: [PATCH 6/7] install.bat and fix error caused with api key --- .yolo-safety-off | 0 install.bat | 20 ++++++++++++++++++++ install.sh | 4 ---- yolo.bat | 2 +- yolo.py | 5 +++-- 5 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 .yolo-safety-off create mode 100644 install.bat diff --git a/.yolo-safety-off b/.yolo-safety-off new file mode 100644 index 0000000..e69de29 diff --git a/install.bat b/install.bat new file mode 100644 index 0000000..23145e6 --- /dev/null +++ b/install.bat @@ -0,0 +1,20 @@ +@echo off +:: Installs yolo in the user's home directory + +::TARGET_DIR=~/yolo-ai-cmdbot +::TARGET_FULLPATH=$TARGET_DIR/yolo.py +set TARGET_DIR= %HOME%yolo-ai-cmdbot +set TARGET_FULLPATH= %TARGET_DIR%\yolo.py + +::mkdir -p $TARGET_DIR +::cp yolo.py prompt.txt $TARGET_DIR +::chmod +x $TARGET_FULLPATH +mkdir %TARGET_DIR% +copy yolo.py %TARGET_DIR% +copy prompt.txt %TARGET_DIR% + +:: Windows: Copies .bat file to $HOME so it works similar to LINUX/MAC, avoiding having to type python.exe every time. +:: Note: Though that maybe making it an executable would make more sense but the + +::Copy to home directory +copy yolo.bat %HOME% \ No newline at end of file diff --git a/install.sh b/install.sh index f46023e..a019293 100644 --- a/install.sh +++ b/install.sh @@ -16,7 +16,3 @@ alias computer=$TARGET_FULLPATH # Add the aliases to the logon scripts echo "alias yolo=$TARGET_FULLPATH" >> ~/.bash_aliases echo "alias computer=$TARGET_FULLPATH" >> ~/.bash_aliases - -# Windows -# Copy yolo.bat to System32 or Home Directory : -cp yolo.bat ~ diff --git a/yolo.bat b/yolo.bat index b958c12..d2cf92f 100644 --- a/yolo.bat +++ b/yolo.bat @@ -1,6 +1,6 @@ @echo off REM Work around to not have to type in python.exe yolo.py every time. -REM Put in C:/Windows/System32 to allow command to work anywhere +REM Put in C:/Windows/System32 or another $PATH directory to allow command to work anywhere python.exe yolo-ai-cmdbot/yolo.py %* \ No newline at end of file diff --git a/yolo.py b/yolo.py index 78e1775..360ae25 100755 --- a/yolo.py +++ b/yolo.py @@ -82,10 +82,11 @@ if __name__ == "__main__": # Two options for the user to specify they openai api key. Windows: Comment out the one you are not using (Causes extra line to appear) - home_path = os.path.expanduser("~") - openai.api_key_path = os.path.join(home_path,".openai.apikey") dotenv.load_dotenv() openai.api_key = os.getenv("OPENAI_API_KEY") + if not openai.api_key: + home_path = os.path.expanduser("~") + openai.api_key_path = os.path.join(home_path,".openai.apikey") # Parse arguments and make sure we have at least a single word if len(sys.argv) < 2: From 67af95d4d5dd265793ea73cf594f9b3b0d85458a Mon Sep 17 00:00:00 2001 From: KAuser2094 Date: Mon, 6 Mar 2023 17:24:16 +0000 Subject: [PATCH 7/7] Edit README, tidy comments --- .yolo-safety-off | 0 README.md | 13 ++++++++++++- install.bat | 23 ++++++++++++++--------- install.sh | 2 +- yolo.bat | 6 ------ yolo.py | 11 ++++++++--- 6 files changed, 35 insertions(+), 20 deletions(-) delete mode 100644 .yolo-safety-off delete mode 100644 yolo.bat diff --git a/.yolo-safety-off b/.yolo-safety-off deleted file mode 100644 index e69de29..0000000 diff --git a/README.md b/README.md index d23fdb5..9c4406a 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,11 @@ Another option is to run `source install.sh` after cloning the repo. That does t That's it. Now make sure you have an OpenAI API key set. +## Installation script (Windows) + +For windows you can run `.\install.bat` (or double-click) after cloning the repo. It will do the following: +1. Copies the necessary files to `~/yolo-ai-cmdbot/` +2. Creates a `yolo.bat` file in `~` that lets you run equivalent to `python.exe ~\yolo-ai-cmdbot\yolo.py` # macOS @@ -43,12 +48,18 @@ Windows is less tested, it does work though and will use PowerShell. `python.exe yolo.py what is my username` +If you use `install.bat` you should have a `yolo.bat` file in your `~` directory that lets you run the command like so: + +`.\yolo.bat what is my username` + +you can put the `yolo.bat` file into a $PATH directory (like `C:\Windows\System32`) to use in any directory + Have fun. # OpenAI API Key configuration There are two ways to configure the key: -- You can either `export OPENAI_API_KEY=` +- You can either `export OPENAI_API_KEY=`, or have a `.env` file in the same directory as `yolo.py` with `OPENAI_API_KEY=""` as a line - Create a file at `~/.openai.apikey` with the key in it # Using yolo diff --git a/install.bat b/install.bat index 23145e6..23d776c 100644 --- a/install.bat +++ b/install.bat @@ -1,20 +1,25 @@ @echo off :: Installs yolo in the user's home directory -::TARGET_DIR=~/yolo-ai-cmdbot -::TARGET_FULLPATH=$TARGET_DIR/yolo.py set TARGET_DIR= %HOME%yolo-ai-cmdbot set TARGET_FULLPATH= %TARGET_DIR%\yolo.py -::mkdir -p $TARGET_DIR -::cp yolo.py prompt.txt $TARGET_DIR -::chmod +x $TARGET_FULLPATH mkdir %TARGET_DIR% copy yolo.py %TARGET_DIR% copy prompt.txt %TARGET_DIR% -:: Windows: Copies .bat file to $HOME so it works similar to LINUX/MAC, avoiding having to type python.exe every time. -:: Note: Though that maybe making it an executable would make more sense but the +:: Windows: Creates a yolo.bat file into %HOME% directory which will let you run similar to Linux/MacOS +:: Example: Input: ".\yolo.bat print hello" to "yolo print hello" -::Copy to home directory -copy yolo.bat %HOME% \ No newline at end of file +:: yolo.bat can only be used in same directory; or, any directory if put in a $PATH directory (type $env:PATH in PowerShell and pick an appropriate path to paste in) +:: C:\Windows\System32 is the $PATH directory everyone is likely to have + +:: Create yolo.bat and if it isn't already there input its code. +find "@echo off" "%HOME%\yolo.bat" && ( + echo "yolo.bat" Already Exists +) || ( + copy /y nul %HOME% yolo.bat + echo @echo off>>"%HOME%yolo.bat" + echo python.exe %HOME%yolo-ai-cmdbot\yolo.py %%*>>"%HOME%\yolo.bat" + echo Created "yolo.bat" in %HOME% +) \ No newline at end of file diff --git a/install.sh b/install.sh index a019293..515666f 100644 --- a/install.sh +++ b/install.sh @@ -15,4 +15,4 @@ alias computer=$TARGET_FULLPATH # Add the aliases to the logon scripts echo "alias yolo=$TARGET_FULLPATH" >> ~/.bash_aliases -echo "alias computer=$TARGET_FULLPATH" >> ~/.bash_aliases +echo "alias computer=$TARGET_FULLPATH" >> ~/.bash_aliases \ No newline at end of file diff --git a/yolo.bat b/yolo.bat deleted file mode 100644 index d2cf92f..0000000 --- a/yolo.bat +++ /dev/null @@ -1,6 +0,0 @@ -@echo off - -REM Work around to not have to type in python.exe yolo.py every time. -REM Put in C:/Windows/System32 or another $PATH directory to allow command to work anywhere - -python.exe yolo-ai-cmdbot/yolo.py %* \ No newline at end of file diff --git a/yolo.py b/yolo.py index 360ae25..bc06396 100755 --- a/yolo.py +++ b/yolo.py @@ -12,7 +12,7 @@ import subprocess from termcolor import colored from colorama import init -import dotenv +import dotenv #Allow .env file to be used # Check if the user globally disabled the safety switch def get_yolo_safety_switch_config(): @@ -81,10 +81,15 @@ if __name__ == "__main__": yolo = "" # user's answer to safety switch (-a) question y/n - # Two options for the user to specify they openai api key. Windows: Comment out the one you are not using (Causes extra line to appear) + # Two options for the user to specify they openai api key. + #1. Place a ".env" file in same directory as this with the line: + # OPENAI_API_KEY="" + # or do `export OPENAI_API_KEY=` before use dotenv.load_dotenv() openai.api_key = os.getenv("OPENAI_API_KEY") - if not openai.api_key: + #2. Place a ".openai.apikey" in the home directory that holds the line: + # + if not openai.api_key: #If statement to avoid "invalid filepath" error home_path = os.path.expanduser("~") openai.api_key_path = os.path.join(home_path,".openai.apikey")