Spaces:
Running on Zero
Running on Zero
File size: 2,604 Bytes
d30bd8e dd6cefc d30bd8e | 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | """Tests for the optional llama.cpp smoke-test helper."""
from __future__ import annotations
import tempfile
import unittest
from pathlib import Path
from unittest.mock import patch
from scripts.check_llama_cpp_smoke import run_llama_cpp_smoke
class FakeLlamaModel:
def __init__(self, responses: list[str]) -> None:
self.responses = responses
def create_chat_completion(self, **_: object) -> dict:
response = self.responses.pop(0)
return {"choices": [{"message": {"content": response}}]}
class LlamaCppSmokeTest(unittest.TestCase):
def test_smoke_passes_when_pipeline_uses_llama_cpp_without_fallback(self) -> None:
fake_llama = FakeLlamaModel(
[
"""
{"persona":{"object_name":"coffee mug","character_name":"Mugworth","mood":"dry and suspicious","secret_fear":"being left empty forever","core_memory":"It remembers every late-night refill.","complaint":"I am treated like a ceramic fuel tank.","tags":["desk witness","warm archive","quiet judgment"]},"diary":{"title":"Secret Diary - Day 418","english":"Today I held another bitter storm and called it service.","chinese":"今天我又装下一场苦涩风暴,并被称为有用。"}}
""",
"""
{"reply":"Mugworth: I saw another deadline dissolve into a coffee ring."}
""",
]
)
with tempfile.TemporaryDirectory() as tmp_dir:
model_path = Path(tmp_dir) / "model.gguf"
model_path.write_text("fake", encoding="utf-8")
with patch("src.models.llama_cpp_runner._load_llama_model", return_value=fake_llama):
result = run_llama_cpp_smoke(
model_path=model_path,
description="old white coffee mug",
mode="Cynical",
save_trace=False,
)
self.assertEqual(result["status"], "pass")
self.assertEqual(result["model_runtime"]["text"], "llama-cpp text generation")
self.assertNotIn("text-fallback-to-mock", result["fallbacks"])
self.assertNotIn("text-fallback-to-mock", result["chat_fallbacks"])
def test_smoke_fails_when_model_path_is_missing(self) -> None:
with self.assertRaises(FileNotFoundError):
run_llama_cpp_smoke(
model_path=Path("/tmp/objectverse-missing-model.gguf"),
description="old white coffee mug",
mode="Cynical",
save_trace=False,
)
if __name__ == "__main__":
unittest.main()
|