OpenCAI / token_filter.py
Norquinal's picture
Upload 2 files
00f8c9a
raw
history blame
1.03 kB
import json
# Load the JSON data from your file
with open('your_json_file_here.json', 'r') as json_file:
data = json.load(json_file)
# Define the minimum values for filtering
minimum_average_token_length = 125 # Set your desired minimum average token length
minimum_conversations_length = 10 # Set your desired minimum length of the 'conversations' array
# Filter the items that meet the minimum criteria
filtered_items = [
item for item in data
if item.get('average_token_length', 0) >= minimum_average_token_length
and len(item.get('conversations', [])) >= minimum_conversations_length
]
# Save the filtered items to a new JSON file
with open('filtered_json_file.json', 'w') as filtered_json_file:
json.dump(filtered_items, filtered_json_file, indent=4)
# Optionally, you can print the filtered items
for i, item in enumerate(filtered_items):
print(f"Filtered Item {i + 1} - Average Token Length: {item.get('average_token_length')}, Conversations Length: {len(item.get('conversations', []))}")