Instructions to use botezx/flagtldr with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Grok
How to use botezx/flagtldr with Grok:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Download classifier/tests/test_service.py from botezx/flagtldr: direct link, hf CLI and curl.
- Browser
- Download file 1.75 kB
-
https://huggingface.co/botezx/flagtldr/resolve/main/classifier/tests/test_service.py
- Command line
-
hf download hf://botezx/flagtldr/classifier/tests/test_service.py
-
curl -L -o test_service.py https://huggingface.co/botezx/flagtldr/resolve/main/classifier/tests/test_service.py
1.75 kB
| import json | |
| from pathlib import Path | |
| import pytest | |
| from fastapi.testclient import TestClient | |
| from xaddons_classifier.backends.basal import build_request, parse_answer | |
| from xaddons_classifier.server import create_app | |
| from xaddons_classifier.spec import LabelSet, Post | |
| LS = json.loads((Path(__file__).parents[2] / "shared" / "labelset.example.json").read_text()) | |
| def test_labelset_validates_and_rejects_unknown_labels(): | |
| LabelSet.model_validate(LS) | |
| bad = dict(LS, examples=[{"text": "x", "label": "nope"}]) | |
| with pytest.raises(ValueError): | |
| LabelSet.model_validate(bad) | |
| def test_classify_endpoint_rules_backend(): | |
| c = TestClient(create_app()) | |
| assert c.get("/health").json()["backend"] == "rules" | |
| r = c.post("/v1/classify", json={"labelset": LS, "posts": [ | |
| {"id": "1", "text": "😂😂😂"}, | |
| {"id": "2", "text": "Według danych GUS inflacja bazowa spadła, teza się nie broni."}, | |
| ]}) | |
| assert r.status_code == 200 | |
| res = r.json()["results"] | |
| assert res["1"]["label"] == "szum" | |
| assert abs(sum(res["2"]["probabilities"].values()) - 1) < 1e-9 | |
| def test_basal_request_and_answer_roundtrip(): | |
| ls = LabelSet.model_validate(LS) | |
| req = build_request(ls, Post(id="1", text="abc", author={"handle": "x"})) | |
| q = req["questions"]["label"] | |
| assert q["type"] == "classify" | |
| assert [l["name"] for l in q["labels"]] == ["merytoryczny", "kontra", "szum"] | |
| assert req["state"]["przyklady_klasyfikacji"][0]["etykieta"] == "kontra" | |
| # answer shape from basal docs/TASKS.md | |
| res = parse_answer({"type": "classify", "label": "kontra", "scores": {"merytoryczny": 0.1, "kontra": 0.85, "szum": 0.05}, "confidence": 0.85}) | |
| assert res.label == "kontra" and res.confidence == 0.85 | |