|
17 | 17 | from rich.table import Table |
18 | 18 | from typing_extensions import Any |
19 | 19 |
|
20 | | -from codeclash.analysis.llm_as_judge.utils import FileLock, Instance, get_instances |
| 20 | +from codeclash.analysis.llm_as_judge.utils import FileLock, Instance, InstanceBatch, get_instances |
21 | 21 | from codeclash.utils.log import get_logger |
22 | 22 |
|
23 | 23 | logger = get_logger("BigQuestionsEvaluator", emoji="🤖") |
@@ -204,17 +204,28 @@ def evaluate_bulk(self, instances: list[Instance], *, n_workers: int = 1) -> Non |
204 | 204 | ) |
205 | 205 |
|
206 | 206 |
|
| 207 | +def load_instances_from_path(path: Path) -> list[Instance]: |
| 208 | + if path.is_file() and path.suffix == ".json": |
| 209 | + logger.info(f"Loading instances from batch file: {path}") |
| 210 | + batch = InstanceBatch.model_validate_json(path.read_text()) |
| 211 | + return batch.instances |
| 212 | + logger.info(f"Loading instances from directory: {path}") |
| 213 | + return get_instances(path) |
| 214 | + |
| 215 | + |
207 | 216 | if __name__ == "__main__": |
208 | 217 | parser = argparse.ArgumentParser() |
209 | | - parser.add_argument("input_dir", type=Path, nargs="+", help="Path to the input dir(s)") |
| 218 | + parser.add_argument( |
| 219 | + "input_dir", type=Path, nargs="+", help="Path to the input dir(s) or to instance batch json files" |
| 220 | + ) |
210 | 221 | parser.add_argument("--shuffle", action="store_true", help="Shuffle instances before processing") |
211 | 222 | parser.add_argument("-n", "--n-workers", type=int, default=1, help="Number of parallel workers (default: 1)") |
212 | 223 | args = parser.parse_args() |
213 | 224 |
|
214 | 225 | config = BigQuestionsConfig.model_validate(yaml.safe_load(config_path.read_text())) |
215 | 226 | instances = [] |
216 | | - for input_dir in args.input_dir: |
217 | | - instances.extend(get_instances(input_dir)) |
| 227 | + for input_path in args.input_dir: |
| 228 | + instances.extend(load_instances_from_path(input_path)) |
218 | 229 | big_questions = BigQuestions(config) |
219 | 230 | if args.shuffle: |
220 | 231 | random.shuffle(instances) |
|
0 commit comments