Spaces:
Running on Zero
Running on Zero
File size: 1,410 Bytes
7f9dfed | 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 | from __future__ import annotations
import unittest
from models.llama_cpp_python_service import LlamaCppPythonService
from models.model_catalog import load_model_catalog
from models.service_factory import create_text_service
class LlamaCppPythonServiceTest(unittest.TestCase):
def test_factory_creates_llama_cpp_python_service(self) -> None:
catalog = load_model_catalog("config/models.yaml")
service = create_text_service(catalog["minicpm5_1b"], "llama-cpp-python")
self.assertIsInstance(service, LlamaCppPythonService)
def test_status_reports_missing_package_or_missing_model(self) -> None:
status = LlamaCppPythonService.status()
self.assertFalse(status.available)
self.assertTrue(
"not installed" in status.detail or "no GGUF model path" in status.detail
)
def test_chat_returns_clear_unavailable_message(self) -> None:
catalog = load_model_catalog("config/models.yaml")
response = LlamaCppPythonService(catalog["minicpm5_1b"]).chat("", "Hello")
self.assertIn("[llama-cpp-python unavailable]", response)
def test_extracts_chat_completion_response(self) -> None:
response = LlamaCppPythonService._extract_response(
{"choices": [{"message": {"content": "hello"}}]}
)
self.assertEqual(response, "hello")
if __name__ == "__main__":
unittest.main()
|