File size: 1,513 Bytes
4807d4b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | """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
|