mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-20 04:14:59 +00:00
feat: Add dummy key to JSON dumps for diffing, then remove it.
This commit is contained in:
parent
2f38cd184c
commit
de28178369
1 changed files with 23 additions and 5 deletions
|
@ -182,15 +182,33 @@ def main():
|
|||
|
||||
# Generate unified diff
|
||||
# If dictionaries differ, generate JSON strings to show the diff
|
||||
litellm_json = json.dumps(litellm_entry, indent=4, sort_keys=True).splitlines()
|
||||
aider_json = json.dumps(aider_entry, indent=4, sort_keys=True).splitlines()
|
||||
# Add a dummy key to ensure the *real* last key gets a comma
|
||||
litellm_entry_copy = litellm_entry.copy()
|
||||
aider_entry_copy = aider_entry.copy()
|
||||
dummy_key = "zzzdummykey"
|
||||
litellm_entry_copy[dummy_key] = True
|
||||
aider_entry_copy[dummy_key] = True
|
||||
|
||||
litellm_json_lines = json.dumps(
|
||||
litellm_entry_copy, indent=4, sort_keys=True
|
||||
).splitlines()
|
||||
aider_json_lines = json.dumps(
|
||||
aider_entry_copy, indent=4, sort_keys=True
|
||||
).splitlines()
|
||||
|
||||
# Remove the dummy key line before diffing
|
||||
litellm_json_filtered = [
|
||||
line for line in litellm_json_lines if dummy_key not in line
|
||||
]
|
||||
aider_json_filtered = [line for line in aider_json_lines if dummy_key not in line]
|
||||
|
||||
diff = difflib.unified_diff(
|
||||
aider_json,
|
||||
litellm_json,
|
||||
aider_json_filtered,
|
||||
litellm_json_filtered,
|
||||
fromfile=f"{key} (aider)",
|
||||
tofile=f"{key} (litellm)",
|
||||
lineterm="",
|
||||
n=max(len(litellm_json), len(aider_json)), # Show all lines
|
||||
n=max(len(litellm_json_filtered), len(aider_json_filtered)), # Show all lines
|
||||
)
|
||||
|
||||
# Print the diff, skipping the header lines generated by unified_diff
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue