Download tests/test_cli.py from CrazyH0rse/Discerna-v1-475M: direct link, hf CLI and curl.
- Browser
- Download file 1.51 kB
-
https://huggingface.co/CrazyH0rse/Discerna-v1-475M/resolve/main/tests/test_cli.py
- Command line
-
hf download hf://CrazyH0rse/Discerna-v1-475M/tests/test_cli.py
-
curl -L -o test_cli.py https://huggingface.co/CrazyH0rse/Discerna-v1-475M/resolve/main/tests/test_cli.py
1.51 kB
| """The `discerna` command on a tiny offline model.""" | |
| import json | |
| from discerna.cli import main | |
| from probes import TEXT_PROBES, circles | |
| from tiny import tiny_folder | |
| def test_decide_prints_json_and_marks_answers(tmp_path, capsys): | |
| folder = tiny_folder(tmp_path / "m", vision=True) | |
| request = tmp_path / "ticket.json" | |
| request.write_text(json.dumps(TEXT_PROBES["ticket"])) | |
| main(["decide", "--model", str(folder), "--device", "cpu", str(request), "--raw"]) | |
| response = json.loads(capsys.readouterr().out) | |
| assert set(response["answers"]) == {"refund", "team", "urgency"} | |
| team = response["answers"]["team"]["choice"] | |
| key = tmp_path / "answers.json" | |
| key.write_text(json.dumps({"ticket.json": {"team": team, "refund": ["yes", "no"]}})) | |
| main(["decide", "--model", str(folder), "--device", "cpu", str(request), "--answers", str(key)]) | |
| out = capsys.readouterr().out | |
| assert "right: 2 of 2" in out and "WRONG" not in out | |
| def test_decide_attaches_images(tmp_path, capsys): | |
| folder = tiny_folder(tmp_path / "m", vision=True) | |
| picture = tmp_path / "c.png" | |
| circles(2).save(picture) | |
| request = tmp_path / "r.json" | |
| request.write_text(json.dumps({"questions": {"two": {"type": "noul", "instructions": "Two circles?"}}})) | |
| main(["decide", "--model", str(folder), "--device", "cpu", str(request), "--image", str(picture), "--raw"]) | |
| response = json.loads(capsys.readouterr().out) | |
| assert response["usage"]["input_tokens"] > 20 # the image prefix was read | |