Initial commit: LocalPilot:本地模型运行时,复用 llama-server 并提供 Ollama 兼容 provider
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import unittest
|
||||
import json
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from localpilot.server import create_app
|
||||
from localpilot.server import _content_to_text, _sse
|
||||
|
||||
|
||||
class ServerHelperTests(unittest.TestCase):
|
||||
def test_content_to_text(self) -> None:
|
||||
self.assertEqual(_content_to_text("hello"), "hello")
|
||||
self.assertEqual(_content_to_text([{"type": "text", "text": "a"}, {"type": "text", "text": "b"}]), "ab")
|
||||
|
||||
def test_sse(self) -> None:
|
||||
value = _sse({"ok": True})
|
||||
self.assertTrue(value.startswith("data: "))
|
||||
self.assertTrue(value.endswith("\n\n"))
|
||||
|
||||
def test_ollama_surface_and_registry(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
path = Path(folder) / "config.json"
|
||||
path.write_text(json.dumps({"models": []}), encoding="utf-8")
|
||||
client = TestClient(create_app(path))
|
||||
self.assertEqual(client.get("/api/version").status_code, 200)
|
||||
self.assertEqual(client.get("/api/tags").json(), {"models": []})
|
||||
registered = client.post("/api/models/register", json={"id": "demo", "kind": "gguf", "path": "E:/demo.gguf"})
|
||||
self.assertEqual(registered.status_code, 200)
|
||||
self.assertEqual(client.get("/api/tags").json()["models"][0]["name"], "demo")
|
||||
created = client.post("/api/create", json={"model": "created", "modelfile": "FROM E:/models/created.gguf\nPARAMETER temperature 0.2"})
|
||||
self.assertEqual(created.status_code, 200)
|
||||
copied = client.post("/api/copy", json={"source": "created", "destination": "created-copy"})
|
||||
self.assertEqual(copied.status_code, 200)
|
||||
removed = client.delete("/api/models/demo")
|
||||
self.assertEqual(removed.status_code, 200)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user