From dea52342ca18b1a2002fb6e2ed3f19cb1cb07ab3 Mon Sep 17 00:00:00 2001 From: Ryuichi Leo Takashige Date: Mon, 2 Feb 2026 17:27:59 +0000 Subject: [PATCH] livecodebench fix --- bench/livecodebench_runner.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/bench/livecodebench_runner.py b/bench/livecodebench_runner.py index 01c70d21..3d9ae141 100644 --- a/bench/livecodebench_runner.py +++ b/bench/livecodebench_runner.py @@ -25,12 +25,35 @@ import argparse import os import sys from datetime import datetime +from pathlib import Path from typing import TYPE_CHECKING if TYPE_CHECKING: from typing import Any +def get_lcb_directory() -> Path | None: + """Find the LiveCodeBench installation directory. + + LiveCodeBench uses relative paths like 'lcb_runner/prompts/few_shot_examples/...' + which require running from the LiveCodeBench directory. + """ + try: + import lcb_runner # pyright: ignore[reportMissingImports] + + # Get the package directory (lcb_runner/) and go up one level to LiveCodeBench/ + lcb_file = lcb_runner.__file__ + if lcb_file is None: + return None + lcb_path = Path(lcb_file).parent.parent + # Verify the expected file exists + if (lcb_path / "lcb_runner" / "prompts" / "few_shot_examples").exists(): + return lcb_path + except ImportError: + pass + return None + + def setup_custom_model(model_name: str, base_url: str) -> None: """Register a custom model in LiveCodeBench's registry.""" try: @@ -122,6 +145,18 @@ def main() -> int: os.environ["OPENAI_API_KEY"] = "exo-local" os.environ["OPENAI_KEY"] = "exo-local" + # Change to LiveCodeBench directory before imports that use relative paths + # LiveCodeBench uses paths like 'lcb_runner/prompts/few_shot_examples/...' + lcb_dir = get_lcb_directory() + if lcb_dir: + os.chdir(lcb_dir) + else: + print( + "Warning: Could not find LiveCodeBench directory. " + "Relative path imports may fail.", + file=sys.stderr, + ) + # Setup custom model and patch client setup_custom_model(args.model, args.base_url) patch_openai_client(args.base_url)