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
|
||||
|
||||
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
|
||||
|
||||
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()
|
||||
|
||||
|
||||
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:
|
||||
original_file_lines = f.readlines()
|
||||
|
||||
|
@ -106,38 +107,38 @@ def apply_changes(file_path, changes_json):
|
|||
else:
|
||||
print(line, end="")
|
||||
|
||||
confirmation = input("Do you want to apply these changes? (y/n): ")
|
||||
if confirmation.lower() == "y":
|
||||
with open(file_path, "w") as f:
|
||||
f.writelines(file_lines)
|
||||
# Checking if user used confirm flag
|
||||
if confirm:
|
||||
confirmation = input("Do you want to apply these changes? (y/n): ")
|
||||
if confirmation.lower() != "y":
|
||||
print("Changes not applied")
|
||||
sys.exit(0)
|
||||
|
||||
# Print explanations
|
||||
cprint("Explanations:", "blue")
|
||||
for explanation in explanations:
|
||||
cprint(f"- {explanation}", "blue")
|
||||
with open(file_path, "w") as f:
|
||||
f.writelines(file_lines)
|
||||
|
||||
# Show the diff
|
||||
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="")
|
||||
# Print explanations
|
||||
cprint("Explanations:", "blue")
|
||||
for explanation in explanations:
|
||||
cprint(f"- {explanation}", "blue")
|
||||
|
||||
print("Changes applied.")
|
||||
# sys.exit(0)
|
||||
# Show the diff
|
||||
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
|
||||
else:
|
||||
print("Changes not applied")
|
||||
sys.exit(0)
|
||||
print("Changes applied.")
|
||||
|
||||
|
||||
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:
|
||||
backup_file = script_name + ".bak"
|
||||
if os.path.exists(backup_file):
|
||||
|
@ -168,7 +169,7 @@ def main(script_name, *script_args, revert=False, model="gpt-4"):
|
|||
error_message=output,
|
||||
model=model,
|
||||
)
|
||||
apply_changes(script_name, json_response)
|
||||
apply_changes(script_name, json_response, confirm=confirm)
|
||||
cprint("Changes applied. Rerunning...", "blue")
|
||||
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue