First routing run¶
This walkthrough gets you from "repo clone" to "routing decisions" in a few minutes. It uses KNNRouter because it is fast and easy to debug.
Related notebook tutorials¶
Prereqs¶
- Install from source so you have
configs/anddata/(see Installation). - If you want full inference (API calls), set
API_KEYS(see Installation).
Step 1: (Optional) Prepare data¶
If you are fine with the example files in data/example_data/, you can skip this step.
Otherwise, run the data preparation notebook:
- https://github.com/ulab-uiuc/LLMRouter/blob/main/notebooks/data_preparation/01_data_preparation.ipynb
Step 2: Train a router (KNN)¶
This should create a model artifact under saved_models/knnrouter/ (as configured in the YAML).
Step 3: Route a single query (no API calls)¶
llmrouter infer --router knnrouter --config configs/model_config_test/knnrouter.yaml --query "Explain transformers." --route-only
Step 4: (Optional) Full inference (routes + calls the selected model)¶
- Ensure your
llm_datahasapi_endpointandmodelfor each candidate model. - Set
API_KEYS.
llmrouter infer --router knnrouter --config configs/model_config_test/knnrouter.yaml --query "Explain transformers."
Step 5: Batch routing/inference¶
Create queries.jsonl:
Route-only batch run:
llmrouter infer --router knnrouter --config configs/model_config_test/knnrouter.yaml --input queries.jsonl --output results.jsonl --output-format jsonl --route-only
Input/output formats are documented in Data formats.
Next¶
- Learn how to interpret the router output: Data formats
- Explore other routers: Routers