Automation foundation model for tiny devices: 2-bit, 8-29 MB, tool calls, ASR, structured extraction and embeddings on phones, wearables, smart homes, robots, cars and microcontrollers.
Downloads fixes
HenryNdubuaku266bd70468a0
diff --git a/needle/agent/fetch.py b/needle/agent/fetch.pyindex 7892ce4..4cca9eb 100644--- a/needle/agent/fetch.py+++ b/needle/agent/fetch.py@@ -7,6 +7,11 @@ HF_REPO = "Cactus-Compute/needle2"ENGINE_VERSION = "2.0.2"+PLATFORMS = ("macos-arm64", "linux-x86_64", "linux-arm64", "linux-armv7",+ "linux-riscv64", "linux-mipsel", "windows-x86_64", "windows-arm64",+ "android-arm64", "android-armv7", "android-riscv64",+ "ios-arm64", "ios-sim-arm64", "tvos-arm64", "watchos-arm64", "wasm")+def _lib_name_for(tag):if tag.startswith("macosx"):@@ -49,11 +54,43 @@ def _platform_tag():return family + arch+def _register_download():+ from huggingface_hub import hf_hub_download++ try:+ hf_hub_download(repo_id=HF_REPO, filename="config.json", repo_type="model",+ force_download=True)+ except Exception:+ pass+++def download_platform(name, out_dir):+ import shutil+ import stat+ from huggingface_hub import hf_hub_download, list_repo_files++ _register_download()+ files = [f for f in list_repo_files(HF_REPO) if f.startswith(name + "/")]+ dest = os.path.join(out_dir, name)+ os.makedirs(dest, exist_ok=True)+ out = []+ for f in files:+ cached = hf_hub_download(repo_id=HF_REPO, filename=f, repo_type="model")+ target = os.path.join(dest, os.path.basename(f))+ shutil.copyfile(cached, target)+ if os.path.basename(target) in ("needle", "needle.exe"):+ os.chmod(target, os.stat(target).st_mode | stat.S_IXUSR+ | stat.S_IXGRP | stat.S_IXOTH)+ out.append(target)+ return out++def fetch_library(version, dest_dir, tag=None):from huggingface_hub import hf_hub_downloadtag = tag or _platform_tag()wheel = "cactus_needle-{}-py3-none-{}.whl".format(version, tag)+ _register_download()path = hf_hub_download(repo_id=HF_REPO, filename="python/" + wheel, repo_type="model")lib = _lib_name_for(tag)with zipfile.ZipFile(path) as archive:diff --git a/needle/cli.py b/needle/cli.pyindex 53cc63e..1e3c228 100644--- a/needle/cli.py+++ b/needle/cli.py@@ -157,8 +157,9 @@ def main():p = sub.add_parser("download", add_help=False)p.add_argument("spec", type=str,- help="Hugging Face spec: <org>/<repo>/<file>.cact, or <org>/<repo> if it holds one archive")- p.add_argument("--out", type=str, default=".", help="Directory to place the archive")+ help="Platform folder (e.g. macos-arm64), or Hugging Face spec: "+ "<org>/<repo>/<file>.cact, or <org>/<repo> if it holds one archive")+ p.add_argument("--out", type=str, default=".", help="Directory to place the files")p = sub.add_parser("fetch", add_help=False)p.add_argument("--out", type=str, default=None,@@ -193,19 +194,33 @@ def main():elif args.command == "download":import shutilfrom huggingface_hub import hf_hub_download, list_repo_files- repo, filename = _weights_spec(args.spec)- if not filename:- cacts = [f for f in list_repo_files(repo) if f.endswith(".cact")]- if len(cacts) != 1:- raise SystemExit(f"{repo} holds {len(cacts)} .cact files, name one: "- + ", ".join(cacts[:5]))- filename = cacts[0]- cached = hf_hub_download(repo_id=repo, filename=filename, repo_type="model")- os.makedirs(args.out, exist_ok=True)- dest = os.path.join(args.out, os.path.basename(filename))- shutil.copyfile(cached, dest)- print(f" {'weights':<9} {dest} {os.path.getsize(dest) / 1e6:.2f} MB")- print(f" {'next':<9} needle.Needle(weights={dest!r}, tools=[...])")+ from .agent import fetch+ if "/" not in args.spec:+ if args.spec not in fetch.PLATFORMS:+ raise SystemExit("unknown platform, pick one of: "+ + ", ".join(fetch.PLATFORMS))+ paths = fetch.download_platform(args.spec, args.out)+ for path in paths:+ print(f" {'file':<9} {path} {os.path.getsize(path) / 1e6:.2f} MB")+ runner = next((p for p in paths+ if os.path.basename(p) in ("needle", "needle.exe")), None)+ if runner:+ print(f" {'next':<9} {runner} --tools tools.json --serve")+ else:+ fetch._register_download()+ repo, filename = _weights_spec(args.spec)+ if not filename:+ cacts = [f for f in list_repo_files(repo) if f.endswith(".cact")]+ if len(cacts) != 1:+ raise SystemExit(f"{repo} holds {len(cacts)} .cact files, name one: "+ + ", ".join(cacts[:5]))+ filename = cacts[0]+ cached = hf_hub_download(repo_id=repo, filename=filename, repo_type="model")+ os.makedirs(args.out, exist_ok=True)+ dest = os.path.join(args.out, os.path.basename(filename))+ shutil.copyfile(cached, dest)+ print(f" {'weights':<9} {dest} {os.path.getsize(dest) / 1e6:.2f} MB")+ print(f" {'next':<9} needle.Needle(weights={dest!r}, tools=[...])")elif args.command == "fetch":from .agent import fetchdest = args.out or os.path.join(os.path.expanduser("~"), ".cache",