Download example.py from SlayerLab/Slayer1B-1.10-Instruct-30.11: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/SlayerLab/Slayer1B-1.10-Instruct-30.11/resolve/main/example.py
- Command line
-
hf download hf://SlayerLab/Slayer1B-1.10-Instruct-30.11/example.py
-
curl -L -o example.py https://huggingface.co/SlayerLab/Slayer1B-1.10-Instruct-30.11/resolve/main/example.py
1.49 kB
| """Chat with Slayer1B 1.10 Instruct 30.11 (one GPU or CPU): pip install torch safetensors tokenizers ; python example.py "What is the capital of Poland?" """ | |
| import sys | |
| from pathlib import Path | |
| import torch | |
| from tokenizers import Tokenizer | |
| HERE = Path(__file__).resolve().parent | |
| sys.path.insert(0, str(HERE)) | |
| import load_slayer # noqa: E402 | |
| from chatfmt import Fmt, parse_calls # noqa: E402 | |
| from model_io import generate # noqa: E402 | |
| device = "cuda" if torch.cuda.is_available() else "cpu" | |
| model = load_slayer.load(str(HERE)) | |
| model = model.to(device=device, dtype=torch.bfloat16 if device == "cuda" else torch.float32) | |
| fmt = Fmt(Tokenizer.from_file(str(HERE / "tokenizer.json"))) | |
| tools = [{"name": "calculator", "description": "Evaluate an arithmetic expression exactly.", | |
| "parameters": {"type": "object", "properties": {"expression": {"type": "string", "description": "Arithmetic expression"}}, "required": ["expression"]}}] | |
| messages = [{"role": "system", "content": "You are Slayer — a private, bilingual (PL/EN) assistant. Use tools only when necessary and never invent their results."}, | |
| {"role": "user", "content": sys.argv[1] if len(sys.argv) > 1 else "What is 18% of 2450?"}] | |
| out, stop = generate(model, fmt.prompt_ids(messages, tools), stop_ids={fmt.ime, fmt.bos}, max_new_tokens=256, device=device) | |
| text = fmt.tok.decode(out, skip_special_tokens=False) | |
| calls, errors = parse_calls(text) | |
| print(text) | |
| print("tool calls to validate and execute:", calls) | |