kopia lustrzana https://github.com/biobootloader/wolverine
don't show diff twice, show explanations before diff
rodzic
472e8b5a87
commit
a1fb03ea81
33
wolverine.py
33
wolverine.py
|
@ -70,7 +70,10 @@ def json_validated_response(model, messages):
|
||||||
messages.append(
|
messages.append(
|
||||||
{
|
{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
"content": "Your response could not be parsed by json.loads. Please restate your last message as pure JSON.",
|
"content": (
|
||||||
|
"Your response could not be parsed by json.loads. "
|
||||||
|
"Please restate your last message as pure JSON."
|
||||||
|
),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
# rerun the api call
|
# rerun the api call
|
||||||
|
@ -146,9 +149,13 @@ def apply_changes(file_path, changes: list, confirm=False):
|
||||||
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 explanations
|
||||||
print("\nChanges to be made:")
|
cprint("Explanations:", "blue")
|
||||||
|
for explanation in explanations:
|
||||||
|
cprint(f"- {explanation}", "blue")
|
||||||
|
|
||||||
|
# Display changes diff
|
||||||
|
print("\nChanges to be made:")
|
||||||
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("+"):
|
||||||
|
@ -158,8 +165,8 @@ def apply_changes(file_path, changes: list, confirm=False):
|
||||||
else:
|
else:
|
||||||
print(line, end="")
|
print(line, end="")
|
||||||
|
|
||||||
# Checking if user used confirm flag
|
|
||||||
if confirm:
|
if confirm:
|
||||||
|
# check if user wants to apply changes or exit
|
||||||
confirmation = input("Do you want to apply these changes? (y/n): ")
|
confirmation = input("Do you want to apply these changes? (y/n): ")
|
||||||
if confirmation.lower() != "y":
|
if confirmation.lower() != "y":
|
||||||
print("Changes not applied")
|
print("Changes not applied")
|
||||||
|
@ -167,24 +174,6 @@ def apply_changes(file_path, changes: list, confirm=False):
|
||||||
|
|
||||||
with open(file_path, "w") as f:
|
with open(file_path, "w") as f:
|
||||||
f.writelines(file_lines)
|
f.writelines(file_lines)
|
||||||
|
|
||||||
# Print explanations
|
|
||||||
cprint("Explanations:", "blue")
|
|
||||||
for explanation in explanations:
|
|
||||||
cprint(f"- {explanation}", "blue")
|
|
||||||
|
|
||||||
# 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("Changes applied.")
|
print("Changes applied.")
|
||||||
|
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue