Spaces:
Running
Running
File size: 1,842 Bytes
6bbf552 a8afc36 6bbf552 b483ca7 a8afc36 6bbf552 a8afc36 6bbf552 | 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 36 37 38 39 40 41 42 43 44 45 46 47 | from pathlib import Path
from ai_runtime import chat_endpoint, local_ai_env, minicpm_server_command, start_minicpm_server
# Verify local chat endpoints use OpenAI-compatible paths.
def test_chat_endpoint() -> None:
assert chat_endpoint(8090) == "http://127.0.0.1:8090/v1/chat/completions"
# Verify the MiniCPM server command points llama.cpp at the GGUF model.
def test_minicpm_server_command() -> None:
command = minicpm_server_command(Path("mini.gguf"), 9000)
assert command[:3] == ("llama-server", "--model", "mini.gguf")
assert "--port" in command
assert "9000" in command
assert "--n-gpu-layers" in command
assert "--parallel" in command
# Verify local AI env forces MiniCPM card generation and Nemotron boss play.
def test_local_ai_env(monkeypatch) -> None:
monkeypatch.setenv("TABRAS_CARD_ENDPOINT", "old")
env = local_ai_env(9001)
assert env["TABRAS_CARD_BACKEND"] == "llamacpp"
assert env["TABRAS_CARD_ENDPOINT"] == "http://127.0.0.1:9001/v1/chat/completions"
assert env["TABRAS_CARD_MAX_TOKENS"] == "256"
assert env["TABRAS_CARD_TEMPERATURE"] == "0.7"
assert env["TABRAS_AI_BOSS"] == "1"
assert env["TABRAS_BOSS_BACKEND"] == "mlx"
assert "Nemotron" in env["TABRAS_BOSS_MODEL"]
assert env["TABRAS_ART_BACKEND"] == "diffusers"
assert env["TABRAS_ART_MODEL"] == "stabilityai/sdxl-turbo"
assert env["TABRAS_ART_WIDTH"] == "512"
assert env["TABRAS_ART_HEIGHT"] == "320"
# Verify starting MiniCPM fails early when the GGUF is absent.
def test_start_minicpm_server_requires_model(tmp_path) -> None:
missing = tmp_path / "missing.gguf"
try:
start_minicpm_server(missing, 9002)
except FileNotFoundError as error:
assert str(missing) in str(error)
else:
raise AssertionError("missing MiniCPM model did not fail")
|