| |
| """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")) |
|
|