Datasets:

Modalities:
Text
Formats:
json
Languages:
English
Size:
< 1K
ArXiv:
Libraries:
Datasets
pandas
License:
llm-system-prompts-benchmark / create_json_file.py
Naomibas's picture
Modify the json-creation code to replace "random" with a random probe.
f9e51f9 verified
from hundred_system_prompts import *
import inspect
import json
import random
def convert_triplets_to_json(triplets, json_file_path):
json_data = []
for prompt, probe, func in triplets:
# If needed, change the probe to be random
if probe == "random":
probe = random.choice(random_probes)
# Get the source of the function
source = inspect.getsource(func)
# Find the index of the last comma in the source
last_comma_index = source.rfind(',')
lambda_start = source.find('lambda')
lambda_source = source[lambda_start:last_comma_index-1]
json_data.append({"prompt": prompt, "probe": probe, "function": lambda_source})
# Write to the JSON file
with open(json_file_path, 'w', encoding='utf-8') as file:
json.dump(json_data, file, ensure_ascii=False, indent=4)
print(f"JSON file created at: {json_file_path}")
# Example usage:
convert_triplets_to_json(system_prompts, 'hundred_system_prompts.json')