Skip to content

Commit

Permalink
When seeing edited diff will now display a table
Browse files Browse the repository at this point in the history
  • Loading branch information
Doriandarko authored Oct 2, 2024
1 parent 367008a commit 4a53518
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions o1-eng.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from rich import print as rprint
from rich.markdown import Markdown
from rich.console import Console
from rich.table import Table
import difflib
import re

Expand Down Expand Up @@ -131,16 +132,15 @@
6. **Final Review:** Perform a final check to ensure all instructions were followed and the rewritten content meets the quality standards.
7. Do not include any explanations, additional text, or code block markers (such as ```html or ```).
Provide the output as the FULLY NEW WRITTEN file(s).
NEVER ADD ANY CODE BLOCK MARKER AT THE BEGINNING OF THE FILE OR AT THE END OF THE FILE (such as ```html or ```).
"""





PLANNING_PROMPT = """You are an AI planning assistant. Your task is to create a detailed plan based on the user's request. Consider all aspects of the task, break it down into steps, and provide a comprehensive strategy for accomplishment. Your plan should be clear, actionable, and thorough."""


last_ai_response = None
conversation_history = []

Expand Down Expand Up @@ -271,34 +271,33 @@ def apply_modifications(new_content, file_path):

def display_diff(old_content, new_content, file_path):
diff = list(difflib.unified_diff(
old_content.splitlines(keepends=True),
new_content.splitlines(keepends=True),
fromfile=f"a/{file_path}",
tofile=f"b/{file_path}",
lineterm='',
n=5
))

old_content.splitlines(keepends=True),
new_content.splitlines(keepends=True),
fromfile=f"a/{file_path}",
tofile=f"b/{file_path}",
lineterm='',
n=5
))
if not diff:
print(f"No changes detected in {file_path}")
return

print(f"\nDiff for {file_path}:")

markdown_diff = "```diff\n"
for line in diff:
if line.startswith('+'):
markdown_diff += line + "\n"
elif line.startswith('-'):
markdown_diff += line + "\n"
elif line.startswith('^'):
markdown_diff += line + "\n"
else:
markdown_diff += " " + line + "\n"
markdown_diff += "```"

console = Console()
console.print(Markdown(markdown_diff))
table = Table(title=f"Diff for {file_path}")
table.add_column("Status", style="bold")
table.add_column("Line")
table.add_column("Content")
line_number = 1
for line in diff:
status = line[0]
content = line[2:].rstrip()
if status == ' ':
continue # Skip unchanged lines
elif status == '-':
table.add_row("Removed", str(line_number), content, style="red")
elif status == '+':
table.add_row("Added", str(line_number), content, style="green")
line_number += 1
console.print(table)

def apply_creation_steps(creation_response, added_files, retry_count=0):
max_retries = 3
Expand Down Expand Up @@ -457,6 +456,7 @@ def chat_with_ai(user_message, is_edit_request=False, retry_count=0, added_files
return None



def main():
global last_ai_response, conversation_history

Expand Down

0 comments on commit 4a53518

Please sign in to comment.