Files
OpenHands/evaluation/swe_bench/scripts/setup/process_output_json_file.py
மனோஜ்குமார் பழனிச்சாமி af9385322b Refactor: Simplify message formatting (#2670)
Removed redundant `str()` conversion in f-string.
2024-06-28 07:34:26 +02:00

36 lines
1.3 KiB
Python

import json
import sys
def process_jsonl(input_file, model_name, output_file):
try:
with open(input_file, 'r') as infile, open(output_file, 'w') as outfile:
data = []
for line in infile:
if line.strip(): # Ensure the line is not empty
json_obj = json.loads(line)
# Create new object with required fields and new model_name
new_obj = {
'instance_id': json_obj['instance_id'],
'model_patch': json_obj['git_patch'],
'model_name_or_path': model_name,
}
data.append(new_obj)
json.dump(
data, outfile, indent=2
) # Write the list of JSON objects to a file
print(f'Output JSON list created at {output_file}')
except Exception as e:
print(f'Error: {e}')
# Usage: python script.py input.jsonl model_name output.json
if __name__ == '__main__':
if len(sys.argv) != 4:
print('Usage: python script.py <input_file> <model_name> <output_file>')
else:
input_file = sys.argv[1]
model_name = sys.argv[2]
output_file = sys.argv[3]
process_jsonl(input_file, model_name, output_file)