MCPcopy Create free account
hub / github.com/InternScience/SciReason / collect_preds

Function collect_preds

tools/collect_code_preds.py:91–124  ·  view source on GitHub ↗
(filename: str)

Source from the content-addressed store, hash-verified

89
90
91def collect_preds(filename: str):
92 # in case the prediction is partial
93 root, ext = osp.splitext(filename)
94 partial_filename = root + '_0' + ext
95 # collect all the prediction results
96 if not osp.exists(osp.realpath(filename)) and not osp.exists(
97 osp.realpath(partial_filename)):
98 print(f'No predictions found for {filename}')
99 return FAILED, None, None
100 else:
101 if osp.exists(osp.realpath(filename)):
102 preds = mmengine.load(filename)
103 pred_strs = [
104 preds[str(i)]['prediction'] for i in range(len(preds))
105 ]
106 ori_prompt_strs = [
107 preds[str(i)]['origin_prompt'] for i in range(len(preds))
108 ]
109 else:
110 filename = partial_filename
111 pred_strs = []
112 ori_prompt_strs = []
113 i = 1
114 while osp.exists(osp.realpath(filename)):
115 preds = mmengine.load(filename)
116 filename = root + f'_{i}' + ext
117 i += 1
118 pred_strs += [
119 preds[str(i)]['prediction'] for i in range(len(preds))
120 ]
121 ori_prompt_strs += [
122 preds[str(i)]['origin_prompt'] for i in range(len(preds))
123 ]
124 return SUCCEED, ori_prompt_strs, pred_strs
125
126
127def main():

Callers 1

mainFunction · 0.85

Calls 1

loadMethod · 0.45

Tested by

no test coverage detected