feat: Maya-Adapter (Managed, gegen Attrappe), Engine-Wahl maya in Registry und CLI (M2.6b)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 08:04:09 +01:00
parent 531a4322ef
commit 07b1ad2d1f
12 changed files with 1213 additions and 12 deletions

View File

@ -26,10 +26,12 @@ from openai import OpenAI
ROOT = Path(__file__).resolve().parents[2]
NEXUS = Path(os.environ.get("NEXUS_BIN", ROOT / "target" / "debug" / "nexus"))
FAKE = ROOT / "crates" / "nexus-adapter" / "tests" / "fake_llama_server.py"
FAKE_MAYA = ROOT / "crates" / "nexus-adapter" / "tests" / "fake_maya.py"
FAKE_OLLAMA = ROOT / "crates" / "nexus-adapter" / "tests" / "fake_ollama.py"
MODEL = "testmodell"
OLLAMA_MODEL = "klein" # Name im Gateway
OLLAMA_TAG = "qwen3:0.6b" # Name in Ollama
MAYA_MODEL = "glm" # Maya-Modell im Gateway
ANTWORT = "Hallo vom Attrappen-Modell."
GEHEIMER_PROMPT = "GEHEIMER-PROMPT-4711"
FALSCHER_KEY = "nx-FALSCHER-SCHLUESSEL-999"
@ -63,6 +65,7 @@ class GatewayTest(unittest.TestCase):
cls.port = free_port()
llama_from = free_port()
ollama_from = free_port()
maya_from = free_port()
cls.config = cls.tmp / "config.toml"
cls.config.write_text(
f'listen = "127.0.0.1:{cls.port}"\n'
@ -82,12 +85,25 @@ class GatewayTest(unittest.TestCase):
f"port_to = {ollama_from + 9}\n"
f"ready_timeout_secs = 20\n\n"
f"[ollama.env]\n"
f'FAKE_OLLAMA_MODE = "ok"\n'
f'FAKE_OLLAMA_MODE = "ok"\n\n'
f"[maya]\n"
f'python = "python3"\n'
f'script = "{FAKE_MAYA}"\n'
f'config_roots = ["{cls.tmp}"]\n'
f"port_from = {maya_from}\n"
f"port_to = {maya_from + 9}\n"
f"ready_timeout_secs = 20\n\n"
f"[maya.env]\n"
f'FAKE_MAYA_MODE = "ok"\n'
f'FAKE_MAYA_LOAD_SECONDS = "0.5"\n'
)
maya_json = cls.tmp / "maya-test.json"
maya_json.write_text(json.dumps({"exe": "/nicht/da", "args": [], "model_name": "fake-maya", "port": 8083}))
model_file = cls.tmp / "modell.gguf"
model_file.write_bytes(b"gguf")
cls.run_cli("model", "add", "--name", MODEL, "--path", str(model_file), "--gpus", "0")
cls.run_cli("model", "add", "--name", OLLAMA_MODEL, "--engine", "ollama", "--tag", OLLAMA_TAG, "--gpus", "0")
cls.run_cli("model", "add", "--name", MAYA_MODEL, "--engine", "maya", "--maya-config", str(maya_json), "--gpus", "0,1")
cls.key = cls.create_key("sdk-normal")
cls.key_vip = cls.create_key("sdk-vip", "--max-priority", "high")
@ -149,6 +165,9 @@ class GatewayTest(unittest.TestCase):
def instance_log(self):
return self.tmp / "data" / "logs" / "instance-1.log"
def maya_log(self):
return self.tmp / "data" / "logs" / "instance-maya-1.log"
def ollama_log(self):
return self.tmp / "data" / "logs" / "instance-ollama.log"
@ -252,6 +271,33 @@ class GatewayTest(unittest.TestCase):
self.assertGreater(len(stuecke), 1)
self.assertTrue("".join(stuecke).endswith(OLLAMA_TAG))
# --- Maya (Port öffnet erst nach dem Laden, reasoning_content, Keep-alive) -----
def test_12_maya_chat_startet_maya_und_reicht_reasoning_durch(self):
self.assertFalse(self.maya_log().exists(), "Die Liste darf Maya nicht starten.")
antwort = self.client.chat.completions.create(
model=MAYA_MODEL, messages=[{"role": "user", "content": "Hallo"}]
)
nachricht = antwort.choices[0].message
self.assertEqual(nachricht.content, "Hallo vom Maya-Modell.")
self.assertEqual((nachricht.model_extra or {}).get("reasoning_content"), "denke")
self.assertTrue(self.maya_log().exists(), "Maya muss gestartet worden sein.")
self.assertIn("--host 127.0.0.1", self.maya_log().read_text())
def test_13_maya_streaming_mit_keep_alive_zeile(self):
stuecke, denken = [], []
for chunk in self.client.chat.completions.create(
model=MAYA_MODEL, messages=[{"role": "user", "content": "Hallo"}], stream=True
):
if chunk.choices:
delta = chunk.choices[0].delta
if delta.content:
stuecke.append(delta.content)
if (delta.model_extra or {}).get("reasoning_content"):
denken.append(delta.model_extra["reasoning_content"])
self.assertEqual("".join(stuecke), " vom Maya-Modell.")
self.assertEqual(denken, ["denke"])
# --- Herunterfahren -------------------------------------------------------
def test_99_herunterfahren_beendet_das_modell(self):
@ -260,8 +306,15 @@ class GatewayTest(unittest.TestCase):
self.assertTrue(pid_alive(pid), "Die Instanz sollte vor dem Herunterfahren laufen.")
ollama_log = self.ollama_log().read_text()
self.assertTrue(pid_alive(int(next(l for l in ollama_log.splitlines() if l.startswith("fake-ollama: pid ")).split()[-1])))
maya_pid = int(next(l for l in self.maya_log().read_text().splitlines() if l.startswith("fake-maya: pid ")).split()[-1])
self.assertTrue(pid_alive(maya_pid))
self.server.send_signal(signal.SIGTERM)
self.assertEqual(self.server.wait(timeout=20), 0)
for _ in range(50):
if not pid_alive(maya_pid):
break
time.sleep(0.1)
self.assertFalse(pid_alive(maya_pid), "Maya läuft nach dem Herunterfahren noch.")
for _ in range(50):
if not pid_alive(pid):
break