MCPcopy Create free account
hub / github.com/OpenCodeInterpreter/OpenCodeInterpreter / script

Function script

evaluation/evalplus/evalplus/sanitize.py:169–237  ·  view source on GitHub ↗
(
    samples: str, inplace: bool = False, debug_task: str = None, mbpp_version="default"
)

Source from the content-addressed store, hash-verified

167
168
169def script(
170 samples: str, inplace: bool = False, debug_task: str = None, mbpp_version="default"
171):
172 # task_id -> entry_point
173 entry_point = {}
174 # merge two datasets
175 dataset = {**get_human_eval_plus(), **get_mbpp_plus(version=mbpp_version)}
176
177 for task_id, problem in dataset.items():
178 entry_point[task_id] = problem["entry_point"]
179
180 # make a new folder with "-sanitized" suffix
181 is_folder = os.path.isdir(samples)
182 target_path = pathlib.Path(samples)
183 if not inplace:
184 if is_folder:
185 new_name = target_path.name + "-sanitized"
186 else:
187 new_name = target_path.name.replace(".jsonl", "-sanitized.jsonl")
188 target_path = target_path.parent / new_name
189 target_path = str(target_path)
190
191 nsan = 0
192 ntotal = 0
193
194 new_solutions = []
195
196 for solution in tqdm(load_solutions(samples)):
197 task_id = solution["task_id"]
198 if task_id not in dataset:
199 print(
200 f"Skiping {task_id} as it does not existing in the latest EvalPlus dataset."
201 )
202 continue
203
204 function_name = entry_point[task_id] if task_id in entry_point else None
205 dbg_identifier = solution["_identifier"]
206 if debug_task is not None and task_id != debug_task:
207 continue
208
209 ntotal += 1
210 if "solution" in solution:
211 old_code = solution["solution"]
212 else:
213 assert "completion" in solution
214 old_code = dataset[task_id]["prompt"] + "\n" + solution["completion"]
215
216 new_code = sanitize(code=old_code, entrypoint=function_name)
217
218 # if changed, print the message
219 if new_code != old_code:
220 msg = "Sanitized: " + dbg_identifier
221 if is_folder:
222 msg += " -> " + dbg_identifier.replace(samples, target_path)
223 print(msg)
224 nsan += 1
225
226 new_solutions.append({"task_id": task_id, "solution": new_code})

Callers

nothing calls this directly

Calls 6

get_human_eval_plusFunction · 0.90
get_mbpp_plusFunction · 0.90
load_solutionsFunction · 0.90
write_directoryFunction · 0.90
write_jsonlFunction · 0.90
sanitizeFunction · 0.70

Tested by

no test coverage detected