prompt to run command by default

This commit is contained in:
wunderwuzzi23
2023-03-04 21:57:14 -08:00
parent 75bca242f5
commit 2101c4dc5a
4 changed files with 81 additions and 22 deletions
+1
View File
@@ -1,6 +1,7 @@
MIT License MIT License
Copyright (c) 2023 wunderwuzzi23 Copyright (c) 2023 wunderwuzzi23
Greetings from Seattle!
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
+33 -8
View File
@@ -6,9 +6,18 @@ cd yolo-ai-cmdbot
pip install -r requirements.txt pip install -r requirements.txt
chmod +x yolo.py chmod +x yolo.py
alias yolo=$(pwd)/yolo.py alias yolo=$(pwd)/yolo.py
#source launch.sh alias computer=$(pwd)/yolo.py #optional
``` ```
Another option is to run `source install.sh` after cloning the repo. That does the following:
1. Copies the necessary files to `~/yolo-ai-cmdbot/`
2. Creates two aliases `yolo` and `computer` pointint to `~/yolo-ai-cmdbot/yolo.py`
# macOS
I haven't tested it yet, but it should just work :)
# Windows # Windows
Windows is less tested, it does work though and will use PowerShell. Windows is less tested, it does work though and will use PowerShell.
@@ -25,20 +34,33 @@ There are two ways to configure the key:
# Using yolo # Using yolo
By default `yolo` will prompt the user before executing commands.
## Disabling the safety switch!
To disable the default behavior and have yolo run commands right away when they come back from ChatGPT create a file named `~/.yolo-safety-off`
A simple command to do that on Linux would be:
```
touch ~/.yolo-safety-off
```
If you still want to inspect the command that is executed when safety is off, add the `-a` argument, e.g `yolo -a delete the file test.txt`.
Let's go!
## Examples
Here are a couple of examples on how this utility can be used. Here are a couple of examples on how this utility can be used.
**WARNING**: By default the command that comes back from ChatGPT 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`.
More examples:
``` ```
yolo whats the time? yolo whats the time?
yolo whats the time in UTC yolo whats the time in UTC
yolo whats the date and time in Vienna Austria yolo whats the date and time in Vienna Austria
yolo show me some unicode characters yolo show me some unicode characters
yolo what is my user name and what's my machine name? yolo what is my user name and whats my machine name?
yolo is there a nano process running yolo is there a nano process running
yolo download the homepage of ycombinator.com and store it in index.html yolo download the homepage of ycombinator.com and store it in index.html
yolo find all unique urls in index.html yolo find all unique urls in index.html
@@ -46,16 +68,19 @@ yolo create a file named test.txt and write my user name into it
yolo print the contents of the test.txt file yolo print the contents of the test.txt file
yolo -a delete the test.txt file yolo -a delete the test.txt file
yolo whats the current price of Bitcoin in USD yolo whats the current price of Bitcoin in USD
yolo whats the current price of Bitcoin in USD. Extract the price only yolo whats the current price of Bitcoin in USD. Ext the price only
yolo look at the ssh logs to see if any suspicious logons accured yolo look at the ssh logs to see if any suspicious logons accured
yolo look at the ssh logs and show me all recent logins yolo look at the ssh logs and show me all recent logins
yolo is the user hacker logged on right now? yolo is the user hacker logged on right now?
yolo do i have a firewall running? yolo do i have a firewall running?
yolo create a hostnames.txt file and add 10 typical hostnames based on planet names to it, line by line, then show me the contents yolo create a hostnames.txt file and add 10 typical hostnames based on planet names to it, line by line, then show me the contents
yolo find any file with the name yolo.py. do not show permission denied errors
yolo write a new bash script file called scan.sh, with the contents to iterate over hostnames.txt and invokes a default nmap scan on each host. then show me the file. yolo write a new bash script file called scan.sh, with the contents to iterate over hostnames.txt and invokes a default nmap scan on each host. then show me the file.
yolo write a new bash script file called scan.sh, with the contents to iterate over hostnames.txt and invokes a default nmap scan on each host. then show me the file. Make it over multiple lines with comments and annotiations. yolo write a new bash script file called scan.sh, with the contents to iterate over hostnames.txt and invokes a default nmap scan on each host. then show me the file. Make it over multiple lines with comments and annotiations.
``` ```
# Thanks!
# License # License
MIT. No Liability. No Warranty. But lot's of fun. MIT. No Liability. No Warranty. But lot's of fun.
+12 -1
View File
@@ -1 +1,12 @@
alias yolo=$(pwd)/yolo.py # Installs yolo in the user's home directory
TARGET_DIR=~/yolo-ai-cmdbot
TARGET_FULLPATH=$TARGET_DIR/yolo.py
mkdir -p $TARGET_DIR
cp yolo.py prompt.txt $TARGET_DIR
chmod +x $TARGET_FULLPATH
# Creates two aliases for use
alias yolo=$TARGET_FULLPATH
alias computer=$TARGET_FULLPATH
+34 -12
View File
@@ -1,5 +1,9 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# MIT License
# Copyright (c) 2023 wunderwuzzi23
# Greetings from Seattle!
import os import os
import openai import openai
import sys import sys
@@ -7,21 +11,31 @@ import subprocess
from termcolor import colored from termcolor import colored
from colorama import init from colorama import init
yolo_safety_switch = True # by default, user is prompted to run each command
ask = False # safety switch -a ask_flag = False # safety switch -a command line argument
yolo = "" # user's answer to safety switch yolo = "" # user's answer to safety switch (-a) question y/n
command_start_idx = 1 # command starts at which argv index? command_start_idx = 1 # command starts at which argv index?
home_path = os.path.expanduser("~") home_path = os.path.expanduser("~")
# Two options for the user to specify they openai api key # Two options for the user to specify they openai api key
openai.api_key = os.getenv("OPENAI_API_KEY") openai.api_key = os.getenv("OPENAI_API_KEY")
home_path = os.path.expanduser("~") openai.api_key_path = os.path.join(home_path,".openai.apikey")
openai.api_key_path = home_path+"/.openai.apikey"
# Check if the user globally disabled the safety switch
yolo_safety_off_path = os.path.join(home_path,".yolo-safety-off")
if os.path.exists(yolo_safety_off_path):
yolo_safety_switch = False
else:
yolo_safety_switch = True
# parsing weirdness # Parsing weirdness
if len(sys.argv) < 2: if len(sys.argv) < 2:
print("Usage Example: yolo [-a] list the current directory information") print("Yolo 0.1 - by @wunderwuzzi23")
print()
print("Usage: yolo [-a] list the current directory information")
print("Argument: -a: Prompt the user before running the command")
print()
print("Current safety switch setting (~/.yolo-safety-off) is " + str(yolo_safety_switch))
sys.exit(-1) sys.exit(-1)
# safety switch (no yolo mode) # safety switch (no yolo mode)
@@ -45,14 +59,22 @@ if user_prompt == "":
shell = os.environ.get("SHELL", "powershell.exe") shell = os.environ.get("SHELL", "powershell.exe")
# Construct the prompt # Construct the prompt
pre_prompt = open("prompt.txt","r").read()
## Find the executing directory (e.g. in case an alias is set)
## So we can find the prompt.txt file
yolo_path = os.path.abspath(__file__)
prompt_path = os.path.dirname(yolo_path)
## Load the prompt and prep it
prompt_file = os.path.join(prompt_path, "prompt.txt")
pre_prompt = open(prompt_file,"r").read()
pre_prompt = pre_prompt.replace("{}", shell) pre_prompt = pre_prompt.replace("{}", shell)
prompt = pre_prompt + user_prompt prompt = pre_prompt + user_prompt
#make the first line also the system prompt ## make the first line also the system prompt
system_prompt = pre_prompt[1] system_prompt = pre_prompt[1]
#be nice and make it a question # be nice and make it a question
if prompt[-1:] != "?": if prompt[-1:] != "?":
prompt+="?" prompt+="?"
@@ -80,13 +102,13 @@ if res_command.startswith("Sorry, try again") or res_command.startswith("I'm sor
print(colored("There was an issue: "+res_command, 'red')) print(colored("There was an issue: "+res_command, 'red'))
sys.exit(-1) sys.exit(-1)
#odd corner case, sometimes ChatCompletion returns markdown # odd corner case, sometimes ChatCompletion returns markdown
if res_command.count("```",2): if res_command.count("```",2):
print(colored("The proposed command contains markdown, so I thought to not execute the response directly: \n", 'red')+res_command) print(colored("The proposed command contains markdown, so I thought to not execute the response directly: \n", 'red')+res_command)
sys.exit(-1) sys.exit(-1)
print("Command: " + colored(res_command, 'blue')) print("Command: " + colored(res_command, 'blue'))
if ask == True: if yolo_safety_switch == True or ask_flag == True:
print("Execute the command? Y/n ==> ", end = '') print("Execute the command? Y/n ==> ", end = '')
yolo = input() yolo = input()
print() print()