Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for flags and .env #21

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Virtual environments
venv
.venv
.env
env/

# Byte-compiled / optimized / DLL files
__pycache__/

# IDE files
.idea/
.vscode/

# Miscellaneous
.DS_Store
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,19 @@ To run with gpt-4 (the default, tested option):

You can also run with other models, but be warned they may not adhere to the edit format as well:

python wolverine.py --model=gpt-3.5-turbo buggy_script.py "subtract" 20 3
python wolverine.py --model=gpt-3.5-turbo -f buggy_script.py "subtract" 20 3


## Flags and their usage

- To run with specific model, pass the `--model` or `-m` flag with model name
- To pass the buggy script name, pass the `-f` or `--flag` flag with script name
- To run the updated changes to the script till success, pass the `-y` or `--yes` flag
- To revert the script to its original state, pass the `-r` or `--revert` flag

## Sample full command

python wolverine.py --model=gpt-3.5-turbo -f buggy_script.py -y "subtract" 20 3

If you want to use GPT-3.5 by default instead of GPT-4 uncomment the default model line in `.env`:

Expand Down
16 changes: 16 additions & 0 deletions args.py
Original file line number Diff line number Diff line change
@@ -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')
23 changes: 20 additions & 3 deletions wolverine.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import shutil
import subprocess
import sys

import openai
from termcolor import cprint
from dotenv import load_dotenv

from args import parser


# Set up the OpenAI API
load_dotenv()
Expand Down Expand Up @@ -187,8 +190,13 @@ def apply_changes(file_path, changes: list, confirm=False):

print("Changes applied.")


def main(script_name, *script_args, revert=False, model=DEFAULT_MODEL, confirm=False):
def main():
args = parser.parse_args()
script_name = args.file
script_args = args.args
revert = args.revert
model = args.model if args.model else DEFAULT_MODEL
run_until_success = args.yes
if revert:
backup_file = script_name + ".bak"
if os.path.exists(backup_file):
Expand All @@ -201,9 +209,18 @@ def main(script_name, *script_args, revert=False, model=DEFAULT_MODEL, confirm=F

# 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")
Expand All @@ -225,4 +242,4 @@ def main(script_name, *script_args, revert=False, model=DEFAULT_MODEL, confirm=F


if __name__ == "__main__":
fire.Fire(main)
main()