2024-11-26 16:20:18 +01:00
|
|
|
import pytest
|
|
|
|
from utils import *
|
|
|
|
|
|
|
|
server = ServerPreset.tinyllama2()
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module", autouse=True)
|
|
|
|
def create_server():
|
|
|
|
global server
|
|
|
|
server = ServerPreset.tinyllama2()
|
|
|
|
|
|
|
|
|
|
|
|
def test_server_start_simple():
|
|
|
|
global server
|
|
|
|
server.start()
|
|
|
|
res = server.make_request("GET", "/health")
|
|
|
|
assert res.status_code == 200
|
|
|
|
|
|
|
|
|
|
|
|
def test_server_props():
|
|
|
|
global server
|
|
|
|
server.start()
|
|
|
|
res = server.make_request("GET", "/props")
|
|
|
|
assert res.status_code == 200
|
2024-12-07 20:21:09 +01:00
|
|
|
assert ".gguf" in res.body["model_path"]
|
2024-11-26 16:20:18 +01:00
|
|
|
assert res.body["total_slots"] == server.n_slots
|
2024-12-07 20:21:09 +01:00
|
|
|
default_val = res.body["default_generation_settings"]
|
|
|
|
assert server.n_ctx is not None and server.n_slots is not None
|
|
|
|
assert default_val["n_ctx"] == server.n_ctx / server.n_slots
|
|
|
|
assert default_val["params"]["seed"] == server.seed
|
2024-11-26 16:20:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_server_models():
|
|
|
|
global server
|
|
|
|
server.start()
|
|
|
|
res = server.make_request("GET", "/models")
|
|
|
|
assert res.status_code == 200
|
|
|
|
assert len(res.body["data"]) == 1
|
|
|
|
assert res.body["data"][0]["id"] == server.model_alias
|
2024-11-29 21:48:56 +01:00
|
|
|
|
2024-12-07 20:21:09 +01:00
|
|
|
|
|
|
|
def test_server_slots():
|
|
|
|
global server
|
|
|
|
|
|
|
|
# without slots endpoint enabled, this should return error
|
|
|
|
server.server_slots = False
|
|
|
|
server.start()
|
|
|
|
res = server.make_request("GET", "/slots")
|
|
|
|
assert res.status_code == 501 # ERROR_TYPE_NOT_SUPPORTED
|
|
|
|
assert "error" in res.body
|
|
|
|
server.stop()
|
|
|
|
|
|
|
|
# with slots endpoint enabled, this should return slots info
|
|
|
|
server.server_slots = True
|
|
|
|
server.n_slots = 2
|
|
|
|
server.start()
|
|
|
|
res = server.make_request("GET", "/slots")
|
|
|
|
assert res.status_code == 200
|
|
|
|
assert len(res.body) == server.n_slots
|
|
|
|
assert server.n_ctx is not None and server.n_slots is not None
|
|
|
|
assert res.body[0]["n_ctx"] == server.n_ctx / server.n_slots
|
|
|
|
assert "params" in res.body[0]
|
|
|
|
assert res.body[0]["params"]["seed"] == server.seed
|
|
|
|
|
|
|
|
|
2024-11-29 21:48:56 +01:00
|
|
|
def test_load_split_model():
|
|
|
|
global server
|
|
|
|
server.model_hf_repo = "ggml-org/models"
|
|
|
|
server.model_hf_file = "tinyllamas/split/stories15M-q8_0-00001-of-00003.gguf"
|
|
|
|
server.model_alias = "tinyllama-split"
|
|
|
|
server.start()
|
|
|
|
res = server.make_request("POST", "/completion", data={
|
|
|
|
"n_predict": 16,
|
|
|
|
"prompt": "Hello",
|
|
|
|
"temperature": 0.0,
|
|
|
|
})
|
|
|
|
assert res.status_code == 200
|
|
|
|
assert match_regex("(little|girl)+", res.body["content"])
|