Skip to content

Commit ea13d7a

Browse files
committed
Fix Issue 1549 & Fix Claude Token Calculate Error.
1 parent beae28d commit ea13d7a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

examples/aflow/optimize.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ def parse_args():
7272
parser.add_argument("--max_rounds", type=int, default=20, help="Max iteration rounds")
7373
parser.add_argument("--check_convergence", type=bool, default=True, help="Whether to enable early stop")
7474
parser.add_argument("--validation_rounds", type=int, default=5, help="Validation rounds")
75-
parser.add_argument("--if_first_optimize", type=bool, default=True, help="Whether it's the first optimization")
75+
parser.add_argument(
76+
"--if_first_optimize",
77+
type=lambda x: x.lower() == "true",
78+
default=True,
79+
help="Whether to download dataset for the first time",
80+
)
7681
return parser.parse_args()
7782

7883

metagpt/ext/aflow/scripts/optimizer_utils/data_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ def __init__(self, root_path: str):
1818
def load_results(self, path: str) -> list:
1919
result_path = os.path.join(path, "results.json")
2020
if os.path.exists(result_path):
21-
return read_json_file(result_path, encoding="utf-8")
21+
with open(result_path, "r") as json_file:
22+
try:
23+
return json.load(json_file)
24+
except json.JSONDecodeError:
25+
return []
2226
return []
2327

2428
def get_top_rounds(self, sample: int, path=None, mode="Graph"):

0 commit comments

Comments
 (0)