Skip to content
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
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
OPENAI_API_KEY=your_api_key
#DEFAULT_MODEL=gpt-3.5-turbo
# suggest using 20 since OpenAI API rate limit(3 / min)
RERUN_INTERVAL=1
23 changes: 23 additions & 0 deletions wolverine/wolverine.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import List, Dict
from termcolor import cprint
from dotenv import load_dotenv
import time

# Set up the OpenAI API
load_dotenv()
Expand All @@ -21,6 +22,9 @@
# Nb retries for json_validated_response, default to -1, infinite
VALIDATE_JSON_RETRY = int(os.getenv("VALIDATE_JSON_RETRY", -1))

# Interval for re-run script, default to 1 second
RERUN_INTERVAL = int(os.getenv("RERUN_INTERVAL", 1))

# Read the system prompt
with open(os.path.join(os.path.dirname(__file__), "..", "prompt.txt"), "r") as f:
SYSTEM_PROMPT = f.read()
Expand Down Expand Up @@ -204,6 +208,15 @@ def check_model_availability(model):
)
exit()

def countdown(seconds):
"""
show a countdown counter
"""
for i in range(seconds, 0, -1):
sys.stdout.write(f"\r{i} seconds left")
sys.stdout.flush()
time.sleep(1)
sys.stdout.write("\rDone!\n")

def main(script_name, *script_args, revert=False, model=DEFAULT_MODEL, confirm=False):
if revert:
Expand All @@ -222,16 +235,23 @@ 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")

rounds_counter = 0

while True:
output, returncode = run_script(script_name, script_args)

if returncode == 0:
cprint("Script ran successfully.", "blue")
cprint(f"Run {rounds_counter} rounds", "yellow")
print("Output:", output)
break

else:
cprint("Script crashed. Trying to fix...", "blue")
# show rounds counter
rounds_counter += 1
cprint(f"Round {rounds_counter}", "yellow")

print("Output:", output)
json_response = send_error_to_gpt(
file_path=script_name,
Expand All @@ -242,3 +262,6 @@ def main(script_name, *script_args, revert=False, model=DEFAULT_MODEL, confirm=F

apply_changes(script_name, json_response, confirm=confirm)
cprint("Changes applied. Rerunning...", "blue")
# wait RERUN_INTERVAL seconds to run next round
countdown(RERUN_INTERVAL)