{"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.10.12"},"kaggle":{"accelerator":"nvidiaL4","dataSources":[{"sourceId":84795,"databundleVersionId":11281725,"sourceType":"competition"},{"sourceId":10974211,"sourceType":"datasetVersion","datasetId":6810506},{"sourceId":10974229,"sourceType":"datasetVersion","datasetId":6770203},{"sourceId":226482247,"sourceType":"kernelVersion"},{"sourceId":236919,"sourceType":"modelInstanceVersion","modelInstanceId":202340,"modelId":224071},{"sourceId":236932,"sourceType":"modelInstanceVersion","modelInstanceId":202348,"modelId":224071}],"dockerImageVersionId":30919,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!pip install /kaggle/input/kprize-akami-deps/*.whl --force-reinstall --root-user-action ignore --no-deps --no-index --find-links /kaggle/input/kprize-akami-deps","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import io\nimport os\nimport shutil\nimport sys\nimport kaggle_evaluation.konwinski_prize_inference_server","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!cp -r /kaggle/input/kprize-akami-codes-kami codes","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from codes.submit import predict_inner, REPO_PATH","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"instance_count = None\n\n\ndef get_number_of_instances(num_instances: int) -> None:\n    \"\"\"The very first message from the gateway will be the total number of instances to be served.\n    You don't need to edit this function.\n    \"\"\"\n    global instance_count\n    instance_count = num_instances","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"skip_prediction = False\n\n\ndef predict(\n    problem_statement: str,\n    repo_archive: io.BytesIO,\n    pip_packages_archive: io.BytesIO,\n    env_setup_cmds_templates: list[str],\n) -> str:\n    \"\"\"\n    Args:\n        problem_statement: The text of the git issue.\n        repo_path: A BytesIO buffer path with a .tar containing the codebase that must be patched. The gateway will make this directory available immediately before this function runs.\n        pip_packages_archive: A BytesIO buffer path with a .tar containing the wheel files necessary for running unit tests.\n        env_setup_cmds_templates: Commands necessary for installing the pip_packages_archive.\n    \"\"\"\n    global skip_prediction\n\n    with open(\"repo_archive.tar\", \"wb\") as f:\n        f.write(repo_archive.read())\n    if os.path.exists(REPO_PATH):\n        shutil.rmtree(REPO_PATH)\n    shutil.unpack_archive(\"repo_archive.tar\", extract_dir=REPO_PATH)\n    os.remove(\"repo_archive.tar\")\n\n    patch_or_None = predict_inner(\n        problem_statement,\n        repo_archive,\n        pip_packages_archive,\n        env_setup_cmds_templates,\n        skip_prediction,\n        save_result=True,\n        difficulty_threshold=0.5,\n        output_dir=\"output/\",\n    )\n\n    shutil.rmtree(REPO_PATH)\n\n    if not os.getenv(\"KAGGLE_IS_COMPETITION_RERUN\"):\n        skip_prediction = True\n\n    return patch_or_None","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"inference_server = kaggle_evaluation.konwinski_prize_inference_server.KPrizeInferenceServer(\n    get_number_of_instances, predict\n)\n\nif os.getenv(\"KAGGLE_IS_COMPETITION_RERUN\"):\n    inference_server.serve()\nelse:\n    inference_server.run_local_gateway(\n        data_paths=(\n            \"/kaggle/input/konwinski-prize/\",  # Path to the entire competition dataset\n            \"/kaggle/tmp/konwinski-prize/\",  # Path to a scratch directory for unpacking data.a_zip.\n        ),\n        use_concurrency=True,  # This can safely be disabled for purposes of local testing if necessary.\n    )","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}