commitcopilot/infer-004
0
1import json2import tarfile3import tempfile4import urllib.request5from pathlib import Path6 7 8def main() -> None:9 api_url = "https://api.github.com/repos/ggml-org/llama.cpp/releases/latest"10 with urllib.request.urlopen(api_url) as response:11 release = json.load(response)12 13 asset = next(14 item15 for item in release["assets"]16 if item["name"].endswith("-bin-ubuntu-x64.tar.gz")17 )18 19 tmp_dir = Path(tempfile.mkdtemp())20 archive = tmp_dir / asset["name"]21 urllib.request.urlretrieve(asset["browser_download_url"], archive)22 23 extract_dir = Path("/opt/llama.cpp")24 extract_dir.mkdir(parents=True, exist_ok=True)25 with tarfile.open(archive, "r:gz") as tar:26 tar.extractall(extract_dir)27 28 server_candidates = list(extract_dir.rglob("llama-server"))29 if not server_candidates:30 raise RuntimeError(f"llama-server not found in {asset['name']}")31 32 for path in extract_dir.rglob("*"):33 if path.is_file() and path.name.startswith(("llama-", "rpc-server")):34 path.chmod(0o755)35 36 target = Path("/usr/local/bin/llama-server")37 if target.exists() or target.is_symlink():38 target.unlink()39 target.symlink_to(server_candidates[0])40 print(f"Installed {release['tag_name']} {asset['name']} -> {server_candidates[0]}")41 42 43if __name__ == "__main__":44 main()45 