Spaces:
Paused
Paused
Download sandbox/skill-defaults.py from Mike0021/pi-web-runtime: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/spaces/Mike0021/pi-web-runtime/resolve/main/sandbox/skill-defaults.py
- Command line
-
hf download hf://spaces/Mike0021/pi-web-runtime/sandbox/skill-defaults.py
-
curl -L -o skill-defaults.py https://huggingface.co/spaces/Mike0021/pi-web-runtime/resolve/main/sandbox/skill-defaults.py
1.07 kB
| """skill-defaults.py <skills dir> <enabled skill>...: the image's skill defaults. The listed skills are on, | |
| every other one is off (`disable-model-invocation: true`: not offered to the model, still usable as | |
| /skill:<name>, and turned on in Pi Web's Settings > Skills). Pi Web keeps a user's own choices in the agent | |
| dir and puts them back on every new machine (lib/skill-choices.ts).""" | |
| import pathlib, re, sys | |
| root, enabled = pathlib.Path(sys.argv[1]), set(sys.argv[2:]) | |
| skills = sorted(root.glob("*/SKILL.md")) | |
| assert any(p.parent.name in enabled for p in skills), f"none of {sorted(enabled)} in {root}" | |
| for skill in skills: | |
| name, text = skill.parent.name, skill.read_text() | |
| head = re.match(r"\A---[ \t]*\n(.*?\n)---", text, re.S) | |
| assert head, f"{name}: no frontmatter" | |
| body = re.sub(r"(?m)^disable-model-invocation:.*\n", "", head.group(1)) | |
| if name not in enabled: | |
| body += "disable-model-invocation: true\n" | |
| skill.write_text(text[: head.start(1)] + body + text[head.end(1):]) | |
| print("on " if name in enabled else "off", name) | |