MCPcopy Create free account
hub / github.com/THUDM/LongWriter / process_data

Function process_data

evaluation/eval_quality.py:63–86  ·  view source on GitHub ↗
(items)

Source from the content-addressed store, hash-verified

61 return None
62
63def process_data(items):
64 for item in tqdm(items):
65 prompt = prompt_template.replace('$INST$', item['prompt']).replace('$RESPONSE$', item["response"])
66 scores = None
67 trys = 0
68 while scores is None and trys < 5:
69 output = get_response_gpt4(prompt)
70 try:
71 if '```json' in output:
72 output = extract_info(r'```json\n(.*?)\n```', output)
73 output = output.replace('\n', '')
74 scores = json.loads(output)
75 for dim in dims:
76 if dim not in scores:
77 scores = None
78 trys += 1
79 except Exception as e:
80 trys += 1
81 if scores is None:
82 print(output)
83 else:
84 item['scores'] = scores
85 fout.write(json.dumps(item, ensure_ascii=False)+'\n')
86 fout.flush()
87
88data = [json.loads(line) for line in prediction_file]
89random.shuffle(data)

Callers

nothing calls this directly

Calls 2

extract_infoFunction · 0.85
get_response_gpt4Function · 0.70

Tested by

no test coverage detected