Squashed commit of the following:
commit 7b16b63f5f269baa0441ee171d906419585d2526 Author: wunderwuzzi23 <johannr@wunderwuzzi.net> Date: Sat Mar 18 19:34:34 2023 -0700 update text commit d99b7ebf211a517d74fcf3241843e78a71e99d05 Author: wunderwuzzi23 <johannr@wunderwuzzi.net> Date: Sat Mar 18 19:31:28 2023 -0700 fix formatting commit 65b1f6218cc32f0a0001637b22b9f1b4640de983 Author: wunderwuzzi23 <johannr@wunderwuzzi.net> Date: Sat Mar 18 19:17:08 2023 -0700 updating messages commit 314071228395a595503dc3a15fda2b3c8b5e6095 Author: wunderwuzzi23 <johannr@wunderwuzzi.net> Date: Sat Mar 18 19:13:40 2023 -0700 updating install.bat for yolo.yaml settings commit 85c9f381415c86e7c95572bdcbd98d6478f616ef Author: wunderwuzzi23 <johannr@wunderwuzzi.net> Date: Sat Mar 18 19:08:09 2023 -0700 load yolo.yaml from executing directory commit d9ee70035e186c8b21875d58e7a7bf3f980eaa60 Author: wunderwuzzi23 <johannr@wunderwuzzi.net> Date: Sat Mar 18 18:43:45 2023 -0700 update readme commit f2ae85827c675e3f2c87bf4d455709e227e1bfb4 Author: wunderwuzzi23 <johannr@wunderwuzzi.net> Date: Sat Mar 18 18:37:41 2023 -0700 cleanup commit fc5cf55982dd6de3a4e81de2b0286f18788bc87c Author: wunderwuzzi23 <johannr@wunderwuzzi.net> Date: Sat Mar 18 18:31:00 2023 -0700 fix formatting commit 3ec4cf959cf4a43d061b0d579c863af5bb495631 Author: wunderwuzzi23 <johannr@wunderwuzzi.net> Date: Sat Mar 18 18:27:49 2023 -0700 set safety: True in config commit d13153141bbdb4ada5d9bf742b19fd9c10624c86 Author: wunderwuzzi23 <johannr@wunderwuzzi.net> Date: Sat Mar 18 18:25:07 2023 -0700 update readme commit 39f82ee8cf744ef6fbfbe6622e4d39cc6323d69a Author: wunderwuzzi23 <johannr@wunderwuzzi.net> Date: Sat Mar 18 18:24:43 2023 -0700 update readme commit 944046c11bdcd3b01b33798dae5ca33e8ddda9db Author: wunderwuzzi23 <johannr@wunderwuzzi.net> Date: Sat Mar 18 18:21:47 2023 -0700 update requirements commit 0c22313bdc6b3a9f272faf99b9998930ede9502a Author: wunderwuzzi23 <johannr@wunderwuzzi.net> Date: Sat Mar 18 18:15:17 2023 -0700 formatting commit 08e16c67ad8fd588962f9bf22fe0588ac4c0ec3a Author: wunderwuzzi23 <johannr@wunderwuzzi.net> Date: Sat Mar 18 17:39:35 2023 -0700 default gpt-3.5-turbo (gpt-4 is waitlist for many) commit eec224fe3b34a2627d771682cde291ccdf96bcac Author: wunderwuzzi23 <johannr@wunderwuzzi.net> Date: Sat Mar 18 17:16:57 2023 -0700 add yolo.yaml, gpt-4 support, improve install.sh
This commit is contained in:
@@ -11,20 +11,21 @@ import sys
|
||||
import subprocess
|
||||
import dotenv
|
||||
import distro
|
||||
import yaml
|
||||
|
||||
from termcolor import colored
|
||||
from colorama import init
|
||||
|
||||
# Check if the user globally disabled the safety switch
|
||||
def get_yolo_safety_switch_config():
|
||||
|
||||
home_path = os.path.expanduser("~")
|
||||
yolo_safety_off_path = os.path.join(home_path,".yolo-safety-off")
|
||||
|
||||
if os.path.exists(yolo_safety_off_path):
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
def read_config() -> any:
|
||||
|
||||
## Find the executing directory (e.g. in case an alias is set)
|
||||
## So we can find the config file
|
||||
yolo_path = os.path.abspath(__file__)
|
||||
prompt_path = os.path.dirname(yolo_path)
|
||||
|
||||
config_file = os.path.join(prompt_path, "yolo.yaml")
|
||||
with open(config_file, 'r') as file:
|
||||
return yaml.safe_load(file)
|
||||
|
||||
# Construct the prompt
|
||||
def get_full_prompt(user_prompt, shell):
|
||||
@@ -48,12 +49,23 @@ def get_full_prompt(user_prompt, shell):
|
||||
return prompt
|
||||
|
||||
def print_usage():
|
||||
print("Yolo 0.1 - by @wunderwuzzi23")
|
||||
print("Yolo v0.2 - by @wunderwuzzi23")
|
||||
print()
|
||||
print("Usage: yolo [-a] list the current directory information")
|
||||
print("Argument: -a: Prompt the user before running the command")
|
||||
print("Argument: -a: Prompt the user before running the command (only useful when safety is off)")
|
||||
print()
|
||||
print("Current safety switch setting (~/.yolo-safety-off) is " + str(yolo_safety_switch))
|
||||
|
||||
yolo_safety_switch = "on"
|
||||
|
||||
if config["safety"] != True:
|
||||
yolo_safety_switch = "off"
|
||||
|
||||
print("Current configuration per yolo.yaml:")
|
||||
print("* Model : " + str(config["model"]))
|
||||
print("* Temperature : " + str(config["temperature"]))
|
||||
print("* Max. Tokens : " + str(config["max_tokens"]))
|
||||
print("* Safety : " + yolo_safety_switch)
|
||||
|
||||
|
||||
def get_os_friendly_name():
|
||||
|
||||
@@ -70,43 +82,50 @@ def get_os_friendly_name():
|
||||
return os_name
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Get the global safety switch setting (default is True/on)
|
||||
yolo_safety_switch = get_yolo_safety_switch_config()
|
||||
|
||||
# Unix based SHELL (/bin/bash, /bin/zsh), otherwise assuming it's Windows
|
||||
shell = os.environ.get("SHELL", "powershell.exe")
|
||||
|
||||
command_start_idx = 1 # Question starts at which argv index?
|
||||
ask_flag = False # safety switch -a command line argument
|
||||
yolo = "" # user's answer to safety switch (-a) question y/n
|
||||
|
||||
|
||||
def set_api_key():
|
||||
# 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="<yourkey>"
|
||||
# or do `export OPENAI_API_KEY=<yourkey>` before use
|
||||
dotenv.load_dotenv()
|
||||
openai.api_key = os.getenv("OPENAI_API_KEY")
|
||||
|
||||
#2. Place a ".openai.apikey" in the home directory that holds the line:
|
||||
# <yourkey>
|
||||
# Note: This options will likely be removed in the future
|
||||
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")
|
||||
|
||||
#3. Final option is the key might be in the yolo.yaml config file
|
||||
# openai_apikey: <yourkey>
|
||||
if not openai.api_key:
|
||||
openai.api_key = config["openai_api_key"]
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
config = read_config()
|
||||
set_api_key()
|
||||
|
||||
# Unix based SHELL (/bin/bash, /bin/zsh), otherwise assuming it's Windows
|
||||
shell = os.environ.get("SHELL", "powershell.exe")
|
||||
|
||||
command_start_idx = 1 # Question starts at which argv index?
|
||||
ask_flag = False # safety switch -a command line argument
|
||||
yolo = "" # user's answer to safety switch (-a) question y/n
|
||||
|
||||
# Parse arguments and make sure we have at least a single word
|
||||
if len(sys.argv) < 2:
|
||||
print_usage()
|
||||
sys.exit(-1)
|
||||
|
||||
# safety switch via argument -a (local override of global setting)
|
||||
# Safety switch via argument -a (local override of global setting)
|
||||
# Force Y/n questions before running the command
|
||||
if sys.argv[1] == "-a":
|
||||
ask_flag = True
|
||||
command_start_idx = 2
|
||||
|
||||
# to allow easy/natural use we don't require the input to be a
|
||||
# To allow easy/natural use we don't require the input to be a
|
||||
# single string. So, the user can just type yolo what is my name?
|
||||
# without having to put the question between ''
|
||||
arguments = sys.argv[command_start_idx:]
|
||||
@@ -117,7 +136,6 @@ if __name__ == "__main__":
|
||||
print ("No user prompt specified.")
|
||||
sys.exit(-1)
|
||||
|
||||
|
||||
# Load the correct prompt based on Shell and OS and append the user's prompt
|
||||
prompt = get_full_prompt(user_prompt, shell)
|
||||
|
||||
@@ -127,13 +145,13 @@ if __name__ == "__main__":
|
||||
|
||||
# Call the ChatGPT API
|
||||
response = openai.ChatCompletion.create(
|
||||
model="gpt-3.5-turbo",
|
||||
model=config["model"],
|
||||
messages=[
|
||||
{"role": "system", "content": system_prompt},
|
||||
{"role": "user", "content": prompt}
|
||||
],
|
||||
temperature=0,
|
||||
max_tokens=500,
|
||||
temperature=config["temperature"],
|
||||
max_tokens=config["max_tokens"],
|
||||
)
|
||||
|
||||
#print (response)
|
||||
@@ -143,8 +161,8 @@ res_command = response.choices[0].message.content.strip()
|
||||
#Enable color output on Windows using colorama
|
||||
init()
|
||||
|
||||
prefixes = ("Sorry", "I'm sorry")
|
||||
if res_command.startswith(prefixes):
|
||||
prefixes = ("sorry", "i'm sorry", "the question is not clear")
|
||||
if res_command.lower().startswith(prefixes):
|
||||
print(colored("There was an issue: "+res_command, 'red'))
|
||||
sys.exit(-1)
|
||||
|
||||
@@ -154,8 +172,8 @@ if res_command.count("```",2):
|
||||
sys.exit(-1)
|
||||
|
||||
print("Command: " + colored(res_command, 'blue'))
|
||||
if yolo_safety_switch == True or ask_flag == True:
|
||||
print("Execute the command? Y/n (default Y) ==> ", end = '')
|
||||
if config["safety"] != "off" or ask_flag == True:
|
||||
print("Execute the command? [Y/n] ==> ", end = '')
|
||||
yolo = input()
|
||||
print()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user