AI-KING-Studio / build_prompts.py
INTERNETCON's picture
Deploy AI KING Studio (CPU basic, MiniMax-H3 excluded, content filter on)
3249e1b verified
Raw History Blame Contribute Delete
1.4 kB
"""Build prompts.json for the Prompt Library tab from ../../images/prompt-pack.md.
Run locally: python build_prompts.py [path/to/prompt-pack.md]
Each fenced code block becomes a card: {section, label, prompt}.
"""
import json, re, sys, pathlib
def parse(md: str):
cards, section, label = [], "General", ""
lines = md.splitlines()
i = 0
while i < len(lines):
ln = lines[i]
if ln.startswith("#"):
section = ln.lstrip("#").strip()
label = ""
elif re.match(r"^\*\*[^*]+\*\*\s*$", ln.strip()):
label = ln.strip().strip("*").strip()
elif ln.strip().startswith("```"):
buf = []
i += 1
while i < len(lines) and not lines[i].strip().startswith("```"):
buf.append(lines[i]); i += 1
text = "\n".join(buf).strip()
if text:
cards.append({"section": section, "label": label or "Prompt", "prompt": text})
i += 1
return cards
if __name__ == "__main__":
here = pathlib.Path(__file__).parent
src = pathlib.Path(sys.argv[1]) if len(sys.argv) > 1 else here.parent.parent / "images" / "prompt-pack.md"
cards = parse(src.read_text(encoding="utf-8"))
(here / "prompts.json").write_text(json.dumps(cards, indent=1, ensure_ascii=False), encoding="utf-8")
print(f"wrote {len(cards)} prompt cards from {src}")