kopia lustrzana https://github.com/biobootloader/wolverine
Add Support for Args Flags and .env
rodzic
1b9649ed7a
commit
0995bd428b
|
@ -0,0 +1 @@
|
|||
OPENAI_API_KEY =
|
|
@ -1,2 +1,13 @@
|
|||
# Virtual environments
|
||||
venv
|
||||
openai_key.txt
|
||||
.env
|
||||
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
|
||||
# IDE files
|
||||
.idea/
|
||||
.vscode/
|
||||
|
||||
# Miscellaneous
|
||||
.DS_Store
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Give your python scripts regenerative healing abilities!'
|
||||
)
|
||||
parser.add_argument('-y', '--yes', help='Run Every Change made by GPT',
|
||||
required=False, action='store_true'
|
||||
)
|
||||
parser.add_argument('-f', '--file', help='Path to buggy file', required=True)
|
||||
parser.add_argument('-m', '--model', help='Model Name', required=False,
|
||||
default='gpt-4'
|
||||
)
|
||||
parser.add_argument('-r', '--revert', help='Revert changes from backup file',
|
||||
required=False, default=False
|
||||
)
|
||||
parser.add_argument('args', nargs='+', help='Arguments to pass to script')
|
|
@ -13,6 +13,7 @@ multidict==6.0.4
|
|||
openai==0.27.2
|
||||
pycodestyle==2.10.0
|
||||
pyflakes==3.0.1
|
||||
python-dotenv==1.0.0
|
||||
requests==2.28.2
|
||||
six==1.16.0
|
||||
termcolor==2.2.0
|
||||
|
|
25
wolverine.py
25
wolverine.py
|
@ -5,13 +5,15 @@ import os
|
|||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from dotenv import load_dotenv
|
||||
from args import parser
|
||||
|
||||
import openai
|
||||
from termcolor import cprint
|
||||
|
||||
# Set up the OpenAI API
|
||||
with open("openai_key.txt") as f:
|
||||
openai.api_key = f.read().strip()
|
||||
load_dotenv()
|
||||
openai.api_key = os.getenv("OPENAI_API_KEY")
|
||||
|
||||
|
||||
def run_script(script_name, script_args):
|
||||
|
@ -114,7 +116,13 @@ def apply_changes(file_path, changes_json):
|
|||
print(line, end="")
|
||||
|
||||
|
||||
def main(script_name, *script_args, revert=False, model="gpt-4"):
|
||||
def main():
|
||||
args = parser.parse_args()
|
||||
script_name = args.file
|
||||
script_args = args.args
|
||||
revert = args.revert
|
||||
model = args.model
|
||||
run_until_success = args.yes
|
||||
if revert:
|
||||
backup_file = script_name + ".bak"
|
||||
if os.path.exists(backup_file):
|
||||
|
@ -127,9 +135,18 @@ def main(script_name, *script_args, revert=False, model="gpt-4"):
|
|||
|
||||
# Make a backup of the original script
|
||||
shutil.copy(script_name, script_name + ".bak")
|
||||
run_first_time = False
|
||||
|
||||
while True:
|
||||
if run_first_time and not run_until_success:
|
||||
cprint("Do you want to run the script again? [y/n]", "blue")
|
||||
user_input = input()
|
||||
while user_input.lower() != "y" and user_input.lower() != "n":
|
||||
cprint("Incorrect entry. Please try again.", "red")
|
||||
if user_input.lower() == "n":
|
||||
break
|
||||
output, returncode = run_script(script_name, script_args)
|
||||
run_first_time = True
|
||||
|
||||
if returncode == 0:
|
||||
cprint("Script ran successfully.", "blue")
|
||||
|
@ -150,4 +167,4 @@ def main(script_name, *script_args, revert=False, model="gpt-4"):
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
fire.Fire(main)
|
||||
main()
|
||||
|
|
Ładowanie…
Reference in New Issue