File size: 643 Bytes
5e39d13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
"""Classify prompts with router-laya-v1 using the `laya` package (PyTorch).

    pip install laya huggingface_hub
    python predict.py "Write a Rust function that parses ISO 8601 dates"
"""
import json
import sys

import laya
from huggingface_hub import hf_hub_download

REPO = "[org]/router-laya-v1"

agent = laya.load(REPO)
questions = json.load(open(hf_hub_download(REPO, "questions.json")))

for prompt in sys.argv[1:] or ["hi there", "Prove that the square root of 2 is irrational"]:
    a = agent.predict(prompt, questions)["answers"]
    print(f"{a['category']['choice']:<18} complexity={a['complexity']['score']:.2f}  {prompt[:60]}")