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 new file mode 100644 index 0000000..23d776c --- /dev/null +++ b/install.bat @@ -0,0 +1,25 @@ +@echo off +:: Installs yolo in the user's home directory + +set TARGET_DIR= %HOME%yolo-ai-cmdbot +set TARGET_FULLPATH= %TARGET_DIR%\yolo.py + +mkdir %TARGET_DIR% +copy yolo.py %TARGET_DIR% +copy prompt.txt %TARGET_DIR% + +:: 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" + +:: 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 73ac811..515666f 100644 --- a/install.sh +++ b/install.sh @@ -7,10 +7,12 @@ mkdir -p $TARGET_DIR cp yolo.py prompt.txt $TARGET_DIR chmod +x $TARGET_FULLPATH +#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 +echo "alias computer=$TARGET_FULLPATH" >> ~/.bash_aliases \ No newline at end of file diff --git a/yolo.py b/yolo.py index 0333f45..bc06396 100755 --- a/yolo.py +++ b/yolo.py @@ -12,6 +12,8 @@ import subprocess from termcolor import colored from colorama import init +import dotenv #Allow .env file to be used + # Check if the user globally disabled the safety switch def get_yolo_safety_switch_config(): @@ -78,10 +80,18 @@ 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("~") + + # 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") - openai.api_key_path = os.path.join(home_path,".openai.apikey") + #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") # Parse arguments and make sure we have at least a single word if len(sys.argv) < 2: @@ -153,4 +163,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)