kopia lustrzana https://github.com/biobootloader/wolverine
commit
2f5a026ff9
|
@ -33,6 +33,10 @@ If you want to use GPT-3.5 by default instead of GPT-4 uncomment the default mod
|
||||||
|
|
||||||
DEFAULT_MODEL=gpt-3.5-turbo
|
DEFAULT_MODEL=gpt-3.5-turbo
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
30
wolverine.py
30
wolverine.py
|
@ -117,7 +117,7 @@ def send_error_to_gpt(file_path, args, error_message, model=DEFAULT_MODEL):
|
||||||
return json_validated_response(model, messages)
|
return json_validated_response(model, messages)
|
||||||
|
|
||||||
|
|
||||||
def apply_changes(file_path, changes: list):
|
def apply_changes(file_path, changes: list, confirm=False):
|
||||||
"""
|
"""
|
||||||
Pass changes as loaded json (list of dicts)
|
Pass changes as loaded json (list of dicts)
|
||||||
"""
|
"""
|
||||||
|
@ -146,6 +146,25 @@ def apply_changes(file_path, changes: list):
|
||||||
elif operation == "InsertAfter":
|
elif operation == "InsertAfter":
|
||||||
file_lines.insert(line, content + "\n")
|
file_lines.insert(line, content + "\n")
|
||||||
|
|
||||||
|
# Ask for user confirmation before writing changes
|
||||||
|
print("\nChanges to be made:")
|
||||||
|
|
||||||
|
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="")
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
|
||||||
with open(file_path, "w") as f:
|
with open(file_path, "w") as f:
|
||||||
f.writelines(file_lines)
|
f.writelines(file_lines)
|
||||||
|
|
||||||
|
@ -156,7 +175,8 @@ def apply_changes(file_path, changes: list):
|
||||||
|
|
||||||
# Show the diff
|
# Show the diff
|
||||||
print("\nChanges:")
|
print("\nChanges:")
|
||||||
diff = difflib.unified_diff(original_file_lines, file_lines, lineterm="")
|
diff = difflib.unified_diff(
|
||||||
|
original_file_lines, file_lines, lineterm="")
|
||||||
for line in diff:
|
for line in diff:
|
||||||
if line.startswith("+"):
|
if line.startswith("+"):
|
||||||
cprint(line, "green", end="")
|
cprint(line, "green", end="")
|
||||||
|
@ -165,8 +185,10 @@ def apply_changes(file_path, changes: list):
|
||||||
else:
|
else:
|
||||||
print(line, end="")
|
print(line, end="")
|
||||||
|
|
||||||
|
print("Changes applied.")
|
||||||
|
|
||||||
def main(script_name, *script_args, revert=False, model=DEFAULT_MODEL):
|
|
||||||
|
def main(script_name, *script_args, revert=False, model=DEFAULT_MODEL, 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):
|
||||||
|
@ -198,7 +220,7 @@ def main(script_name, *script_args, revert=False, model=DEFAULT_MODEL):
|
||||||
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