MCPcopy Create free account
hub / github.com/GAIR-NLP/factool / PostProcessor

Class PostProcessor

factool/code/helper/postprocess.py:10–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8STOP_TOKEN = ['\nclass', '\ndef', '\n#', '\nif', '\nprint']
9
10class PostProcessor:
11 @staticmethod
12 def map_task_id_for_solution(predict_path, source_path):
13 database = dict()
14 raw_problems = Tools.load_tasks(source_path)
15 for task_id in raw_problems.keys():
16 database[raw_problems[task_id]['prompt']] = raw_problems[task_id]
17
18 result = []
19 predictions = Tools.load_jsonl(predict_path)
20
21 for pre in predictions:
22 task = database[pre['prompt']]
23
24 for sample in pre['samples']:
25 processed_code = PostProcessor.solution_extract(sample)
26 result.append({
27 'task_id': task['task_id'],
28 'prompt': pre['prompt'],
29 'test': task['test'],
30 'entry_point': task['entry_point'],
31 'completion': processed_code
32 })
33 return result, len(raw_problems)
34
35 @staticmethod
36 def solution_extract(content):
37 for identifier in STOP_TOKEN:
38 if identifier in content:
39 content = content.split(identifier)[0]
40 return content

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected