kopia lustrzana https://github.com/biobootloader/wolverine
updated the flag --confirm as required
- Updated the flag --confirm=True which will allow user to say yes or no before making changes to the file. - If flag is not used then it will right away make changes to the file. - Updated the readme with an example.pull/16/head
rodzic
e65a4d080a
commit
e1c413fae2
|
@ -26,6 +26,10 @@ You can also run with other models, but be warned they may not adhere to the edi
|
||||||
|
|
||||||
python wolverine.py --model=gpt-3.5-turbo buggy_script.py "subtract" 20 3
|
python wolverine.py --model=gpt-3.5-turbo buggy_script.py "subtract" 20 3
|
||||||
|
|
||||||
|
You can also use flag `--confirm=True` which will ask you `yes or no` before making changes to the file. If flag is not used then it will apply the changes to the file
|
||||||
|
|
||||||
|
python wolverine.py buggy_script.py "subtract" 20 3 --confirm=True
|
||||||
|
|
||||||
## Future Plans
|
## Future Plans
|
||||||
|
|
||||||
This is just a quick prototype I threw together in a few hours. There are many possible extensions and contributions are welcome:
|
This is just a quick prototype I threw together in a few hours. There are many possible extensions and contributions are welcome:
|
||||||
|
|
57
wolverine.py
57
wolverine.py
|
@ -66,7 +66,8 @@ def send_error_to_gpt(file_path, args, error_message, model):
|
||||||
return response.choices[0].message.content.strip()
|
return response.choices[0].message.content.strip()
|
||||||
|
|
||||||
|
|
||||||
def apply_changes(file_path, changes_json):
|
# Added the flag confirm. Once user use flag confirm then it will ask for confirmation before applying the changes.
|
||||||
|
def apply_changes(file_path, changes_json, confirm=False):
|
||||||
with open(file_path, "r") as f:
|
with open(file_path, "r") as f:
|
||||||
original_file_lines = f.readlines()
|
original_file_lines = f.readlines()
|
||||||
|
|
||||||
|
@ -106,38 +107,38 @@ def apply_changes(file_path, changes_json):
|
||||||
else:
|
else:
|
||||||
print(line, end="")
|
print(line, end="")
|
||||||
|
|
||||||
confirmation = input("Do you want to apply these changes? (y/n): ")
|
# Checking if user used confirm flag
|
||||||
if confirmation.lower() == "y":
|
if confirm:
|
||||||
with open(file_path, "w") as f:
|
confirmation = input("Do you want to apply these changes? (y/n): ")
|
||||||
f.writelines(file_lines)
|
if confirmation.lower() != "y":
|
||||||
|
print("Changes not applied")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
# Print explanations
|
with open(file_path, "w") as f:
|
||||||
cprint("Explanations:", "blue")
|
f.writelines(file_lines)
|
||||||
for explanation in explanations:
|
|
||||||
cprint(f"- {explanation}", "blue")
|
|
||||||
|
|
||||||
# Show the diff
|
# Print explanations
|
||||||
print("\nChanges:")
|
cprint("Explanations:", "blue")
|
||||||
diff = difflib.unified_diff(
|
for explanation in explanations:
|
||||||
original_file_lines, file_lines, lineterm="")
|
cprint(f"- {explanation}", "blue")
|
||||||
for line in diff:
|
|
||||||
if line.startswith("+"):
|
|
||||||
cprint(line, "green", end="")
|
|
||||||
elif line.startswith("-"):
|
|
||||||
cprint(line, "red", end="")
|
|
||||||
else:
|
|
||||||
print(line, end="")
|
|
||||||
|
|
||||||
print("Changes applied.")
|
# Show the diff
|
||||||
# sys.exit(0)
|
print("\nChanges:")
|
||||||
|
diff = difflib.unified_diff(
|
||||||
|
original_file_lines, file_lines, lineterm="")
|
||||||
|
for line in diff:
|
||||||
|
if line.startswith("+"):
|
||||||
|
cprint(line, "green", end="")
|
||||||
|
elif line.startswith("-"):
|
||||||
|
cprint(line, "red", end="")
|
||||||
|
else:
|
||||||
|
print(line, end="")
|
||||||
|
|
||||||
# Ending the code once they hit n or N
|
print("Changes applied.")
|
||||||
else:
|
|
||||||
print("Changes not applied")
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
|
|
||||||
def main(script_name, *script_args, revert=False, model="gpt-4"):
|
# Added the flag confirm. Once user use flag confirm then it will ask for confirmation before applying the changes.
|
||||||
|
def main(script_name, *script_args, revert=False, model="gpt-4", confirm=False):
|
||||||
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):
|
||||||
|
@ -168,7 +169,7 @@ def main(script_name, *script_args, revert=False, model="gpt-4"):
|
||||||
error_message=output,
|
error_message=output,
|
||||||
model=model,
|
model=model,
|
||||||
)
|
)
|
||||||
apply_changes(script_name, json_response)
|
apply_changes(script_name, json_response, confirm=confirm)
|
||||||
cprint("Changes applied. Rerunning...", "blue")
|
cprint("Changes applied. Rerunning...", "blue")
|
||||||
|
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue