diff --git a/examples/aflow/optimize.py b/examples/aflow/optimize.py index 62df68585..d07eab993 100644 --- a/examples/aflow/optimize.py +++ b/examples/aflow/optimize.py @@ -72,7 +72,12 @@ def parse_args(): parser.add_argument("--max_rounds", type=int, default=20, help="Max iteration rounds") parser.add_argument("--check_convergence", type=bool, default=True, help="Whether to enable early stop") parser.add_argument("--validation_rounds", type=int, default=5, help="Validation rounds") - parser.add_argument("--if_first_optimize", type=bool, default=True, help="Whether it's the first optimization") + parser.add_argument( + "--if_first_optimize", + type=lambda x: x.lower() == "true", + default=True, + help="Whether to download dataset for the first time", + ) return parser.parse_args() diff --git a/metagpt/ext/aflow/scripts/optimizer_utils/data_utils.py b/metagpt/ext/aflow/scripts/optimizer_utils/data_utils.py index 2df161ed8..2a09e0820 100644 --- a/metagpt/ext/aflow/scripts/optimizer_utils/data_utils.py +++ b/metagpt/ext/aflow/scripts/optimizer_utils/data_utils.py @@ -18,7 +18,11 @@ class DataUtils: def load_results(self, path: str) -> list: result_path = os.path.join(path, "results.json") if os.path.exists(result_path): - return read_json_file(result_path, encoding="utf-8") + with open(result_path, "r") as json_file: + try: + return json.load(json_file) + except json.JSONDecodeError: + return [] return [] def get_top_rounds(self, sample: int, path=None, mode="Graph"):