初始化项目,由ModelHub XC社区提供模型
Model: Shpigford/cron-mini Source: Original Platform
This commit is contained in:
22
example.py
Normal file
22
example.py
Normal file
@@ -0,0 +1,22 @@
|
||||
#!/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"))
|
||||
Reference in New Issue
Block a user