diff --git a/examples/ags/benchmark/humaneval.py b/examples/ags/benchmark/humaneval.py index c029ad23b..ec1a3402d 100644 --- a/examples/ags/benchmark/humaneval.py +++ b/examples/ags/benchmark/humaneval.py @@ -71,13 +71,11 @@ async def samples_generate(mode: ModeType, result_path: str = "samples.jsonl"): ids = list(get_human_eval_plus().keys()) file_lock = asyncio.Lock() - @handle_exception( - exception_type=Exception, - exception_msg="Error in solve_and_write function", - default_return=lambda id, *args, **kwargs: id, - ) async def solve_and_write(id: str, mode: ModeType) -> Optional[str]: - sample_dict = await route_generate(mode, id) + try: + sample_dict = await route_generate(mode, id) + except Exception: + return id async with file_lock: async with aiofiles.open(result_path, mode="a") as f: await f.write(json.dumps(sample_dict) + "\n") diff --git a/metagpt/actions/action_node.py b/metagpt/actions/action_node.py index ef0414ff7..a09d4a1da 100644 --- a/metagpt/actions/action_node.py +++ b/metagpt/actions/action_node.py @@ -539,7 +539,7 @@ class ActionNode: if self.schema: schema = self.schema - if mode == self.MODE_CODE_FILL: + if mode == MODE_CODE_FILL: result = await self.code_fill(context, function_name, timeout) self.instruct_content = self.create_class()(**result) return self diff --git a/metagpt/utils/common.py b/metagpt/utils/common.py index 7bed9e9b7..47f2768cd 100644 --- a/metagpt/utils/common.py +++ b/metagpt/utils/common.py @@ -595,15 +595,14 @@ def read_jsonl_file(jsonl_file: str, encoding="utf-8") -> list[dict]: return datas -def add_jsonl_file(jsonl_file: str, data: list[dict], encoding: str = None, indent: int = 4): +def add_jsonl_file(jsonl_file: str, data: list[dict], encoding: str = None): folder_path = Path(jsonl_file).parent if not folder_path.exists(): folder_path.mkdir(parents=True, exist_ok=True) with open(jsonl_file, "a", encoding=encoding) as fout: for json_item in data: - json_str = json.dumps(json_item, indent=indent) - fout.write(json_str + "\n") + fout.write(json.dumps(json_item) + "\n") def read_csv_to_list(curr_file: str, header=False, strip_trail=True):