Team Ai
Apppublic

KBaba7/llama.cpp

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
0likes
test_tokenize.py60 linesDownload Raw Back to unit
1import pytest2from utils import *3 4server = ServerPreset.tinyllama2()5 6 7@pytest.fixture(scope="module", autouse=True)8def create_server():9    global server10    server = ServerPreset.tinyllama2()11 12 13def test_tokenize_detokenize():14    global server15    server.start()16    # tokenize17    content = "What is the capital of France ?"18    res_tok = server.make_request("POST", "/tokenize", data={19        "content": content20    })21    assert res_tok.status_code == 20022    assert len(res_tok.body["tokens"]) > 523    # detokenize24    res_detok = server.make_request("POST", "/detokenize", data={25        "tokens": res_tok.body["tokens"],26    })27    assert res_detok.status_code == 20028    assert res_detok.body["content"].strip() == content29 30 31def test_tokenize_with_bos():32    global server33    server.start()34    # tokenize35    content = "What is the capital of France ?"36    bosId = 137    res_tok = server.make_request("POST", "/tokenize", data={38        "content": content,39        "add_special": True,40    })41    assert res_tok.status_code == 20042    assert res_tok.body["tokens"][0] == bosId43 44 45def test_tokenize_with_pieces():46    global server47    server.start()48    # tokenize49    content = "This is a test string with unicode 媽 and emoji 🤗"50    res_tok = server.make_request("POST", "/tokenize", data={51        "content": content,52        "with_pieces": True,53    })54    assert res_tok.status_code == 20055    for token in res_tok.body["tokens"]:56        assert "id" in token57        assert token["id"] > 058        assert "piece" in token59        assert len(token["piece"]) > 060