From 82b26daf37e25d3a6e3a3ebce0a0857185180823 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Sun, 20 Apr 2025 11:00:49 -0700 Subject: [PATCH] feat: display matching entries side-by-side with diff highlighting --- scripts/clean_metadata.py | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/scripts/clean_metadata.py b/scripts/clean_metadata.py index dcdfbb5f4..defca1606 100644 --- a/scripts/clean_metadata.py +++ b/scripts/clean_metadata.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import json +import difflib from pathlib import Path import json5 @@ -43,12 +44,42 @@ def main(): litellm_keys = set(litellm_data.keys()) aider_keys = set(aider_data.keys()) - common_keys = litellm_keys.intersection(aider_keys) + common_keys = sorted(list(litellm_keys.intersection(aider_keys))) if common_keys: - print("Common models found in both files:") - for key in sorted(list(common_keys)): - print(f"- {key}") + print("Comparing common models found in both files:\n") + for key in common_keys: + print(f"--- {key} (litellm) ---") + print(f"+++ {key} (aider) +++") + + litellm_entry = litellm_data.get(key, {}) + aider_entry = aider_data.get(key, {}) + + # Convert dicts to formatted JSON strings for comparison + litellm_json = json.dumps(litellm_entry, indent=4, sort_keys=True).splitlines() + aider_json = json.dumps(aider_entry, indent=4, sort_keys=True).splitlines() + + # Generate unified diff + diff = difflib.unified_diff( + litellm_json, + aider_json, + fromfile=f"{key} (litellm)", + tofile=f"{key} (aider)", + lineterm="", + n=max(len(litellm_json), len(aider_json)), # Show all lines + ) + + # Print the diff, skipping the header lines generated by unified_diff + diff_lines = list(diff)[2:] + if not diff_lines: + print("(No differences found)") + else: + for line in diff_lines: + # Add color for better readability (optional, requires a library like 'termcolor' or manual ANSI codes) + # Simple +/- indication is standard for diffs + print(line) + print("\n" + "=" * 40 + "\n") + else: print("No common models found between the two files.")