kopia lustrzana https://github.com/biobootloader/wolverine
feat: ✨ can debug javascript files
rodzic
1b9649ed7a
commit
3d14f31511
31
wolverine.py
31
wolverine.py
|
@ -25,6 +25,17 @@ def run_script(script_name, script_args):
|
||||||
return result.decode("utf-8"), 0
|
return result.decode("utf-8"), 0
|
||||||
|
|
||||||
|
|
||||||
|
def run_node(script_name, script_args):
|
||||||
|
script_args = [str(arg) for arg in script_args]
|
||||||
|
try:
|
||||||
|
result = subprocess.check_output(
|
||||||
|
["node", script_name, *script_args], stderr=subprocess.STDOUT
|
||||||
|
)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
return e.output.decode("utf-8"), e.returncode
|
||||||
|
return result.decode("utf-8"), 0
|
||||||
|
|
||||||
|
|
||||||
def send_error_to_gpt(file_path, args, error_message, model):
|
def send_error_to_gpt(file_path, args, error_message, model):
|
||||||
with open(file_path, "r") as f:
|
with open(file_path, "r") as f:
|
||||||
file_lines = f.readlines()
|
file_lines = f.readlines()
|
||||||
|
@ -38,8 +49,7 @@ def send_error_to_gpt(file_path, args, error_message, model):
|
||||||
initial_prompt_text = f.read()
|
initial_prompt_text = f.read()
|
||||||
|
|
||||||
prompt = (
|
prompt = (
|
||||||
initial_prompt_text +
|
initial_prompt_text + "\n\n"
|
||||||
"\n\n"
|
|
||||||
"Here is the script that needs fixing:\n\n"
|
"Here is the script that needs fixing:\n\n"
|
||||||
f"{file_with_lines}\n\n"
|
f"{file_with_lines}\n\n"
|
||||||
"Here are the arguments it was provided:\n\n"
|
"Here are the arguments it was provided:\n\n"
|
||||||
|
@ -114,7 +124,7 @@ def apply_changes(file_path, changes_json):
|
||||||
print(line, end="")
|
print(line, end="")
|
||||||
|
|
||||||
|
|
||||||
def main(script_name, *script_args, revert=False, model="gpt-4"):
|
def main(script_name, *script_args, revert=False, model="gpt-3.5-turbo"):
|
||||||
if revert:
|
if revert:
|
||||||
backup_file = script_name + ".bak"
|
backup_file = script_name + ".bak"
|
||||||
if os.path.exists(backup_file):
|
if os.path.exists(backup_file):
|
||||||
|
@ -129,7 +139,12 @@ def main(script_name, *script_args, revert=False, model="gpt-4"):
|
||||||
shutil.copy(script_name, script_name + ".bak")
|
shutil.copy(script_name, script_name + ".bak")
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
output, returncode = run_script(script_name, script_args)
|
output = ""
|
||||||
|
returncode = 0
|
||||||
|
if script_name.endswith(".js"):
|
||||||
|
output, returncode = run_node(script_name, script_args)
|
||||||
|
else:
|
||||||
|
output, returncode = run_script(script_name, script_args)
|
||||||
|
|
||||||
if returncode == 0:
|
if returncode == 0:
|
||||||
cprint("Script ran successfully.", "blue")
|
cprint("Script ran successfully.", "blue")
|
||||||
|
@ -140,10 +155,10 @@ def main(script_name, *script_args, revert=False, model="gpt-4"):
|
||||||
print("Output:", output)
|
print("Output:", output)
|
||||||
|
|
||||||
json_response = send_error_to_gpt(
|
json_response = send_error_to_gpt(
|
||||||
file_path=script_name,
|
file_path=script_name,
|
||||||
args=script_args,
|
args=script_args,
|
||||||
error_message=output,
|
error_message=output,
|
||||||
model=model,
|
model=model,
|
||||||
)
|
)
|
||||||
apply_changes(script_name, json_response)
|
apply_changes(script_name, json_response)
|
||||||
cprint("Changes applied. Rerunning...", "blue")
|
cprint("Changes applied. Rerunning...", "blue")
|
||||||
|
|
Ładowanie…
Reference in New Issue