File size: 980 Bytes
fdf2e12 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #!/usr/bin/env python3
"""Minimal inference example for Shpigford/cron-mini."""
from mlx_lm import load, generate
model, tokenizer = load("Shpigford/cron-mini")
SYSTEM = ("You convert natural-language schedules into cron expressions and "
"systemd OnCalendar strings. Output JSON with keys: cron, systemd, "
"note. If cron cannot exactly express the schedule, put the closest "
"valid cron and explain in note. Do not output anything else.")
def schedule_to_cron(nl: str) -> str:
messages = [
{"role": "system", "content": SYSTEM},
{"role": "user", "content": f"Convert this schedule to cron and systemd OnCalendar: {nl}"},
]
prompt = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
return generate(model, tokenizer, prompt=prompt, max_tokens=200, temp=0.0)
if __name__ == "__main__":
import sys
print(schedule_to_cron(" ".join(sys.argv[1:]) or "every weekday at 9am"))
|