feat(ui): Playground liest Antworten vor (Sprachmodell, Stimme, Vorlesen-Knopf) (#1100)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GmHhg3Td16J38kAyDLzb39
This commit is contained in:
2026-11-17 20:15:24 +01:00
parent d21f8d871f
commit 3049d063ca
6 changed files with 320 additions and 17 deletions

View File

@ -310,6 +310,22 @@ async fn gateway_with(
})
.unwrap();
}
// Ein Sprachmodell (Engine `tts`), das wie alle anderen auf die Attrappe zeigt.
store
.register_llm(&NewLlm {
name: "sprecher".to_string(),
engine: "tts".to_string(),
path: PathBuf::from("Qwen/Qwen3-TTS-12Hz-1.7B-Base"),
quantization: None,
size_bytes: None,
gpus: vec![0],
context: None,
vram_mb,
ram_mb: None,
idle_secs: None,
enabled: true,
})
.unwrap();
let key = store
.create_api_key(
"alle",
@ -387,6 +403,7 @@ async fn gateway_with(
let mut engines: HashMap<String, Arc<dyn Engine>> = HashMap::new();
engines.insert("llama.cpp".to_string(), engine.clone());
engines.insert("tts".to_string(), engine.clone());
let state = AppState::new(store, Runtime::with_options(engines, options));
let port = serve(nexus_api::router(state.clone())).await;
Gateway {
@ -464,7 +481,7 @@ async fn modellliste_zeigt_freigegebene_modelle_je_nach_rechten_auch_ungeladene(
let (status, _, body) = gw.get("/v1/models", Some(&gw.key)).await;
assert_eq!(status, 200);
assert_eq!(body["object"], "list");
assert_eq!(ids(&body), ["bonsai", "zweit"]);
assert_eq!(ids(&body), ["bonsai", "sprecher", "zweit"]);
assert_eq!(body["data"][0]["object"], "model");
let (_, _, body) = gw.get("/v1/models", Some(&gw.key_bonsai)).await;
assert_eq!(ids(&body), ["bonsai"]);
@ -2276,6 +2293,61 @@ async fn playground(
req.send().await.unwrap()
}
#[tokio::test]
async fn playground_liest_vor_nur_mit_sprachmodell_und_sitzung() {
let gw = gateway(0, false).await;
let (cookie, csrf) = ui_session(&gw, &gw.key_admin).await;
// Das Sprachmodell steht bei der Sprachausgabe, nicht in der Modellwahl des Chats.
let (_, _, seite) = ui_get(&gw, "/ui/chat", Some(&cookie)).await;
assert!(seite.contains("id=\"chat-sprache\"") && seite.contains("<option value=\"sprecher\">"));
let chat_wahl = seite
.split("id=\"chat-modell\"")
.nth(1)
.and_then(|t| t.split("</select>").next())
.unwrap();
assert!(chat_wahl.contains("bonsai") && !chat_wahl.contains("sprecher"));
let sprechen = |cookie: String, csrf: Option<String>, body: Value| {
let mut req = gw
.client
.post(format!("{}/ui/chat/sprechen", gw.base))
.header("origin", &gw.base)
.header("cookie", cookie)
.header(CONTENT_TYPE, "application/json")
.body(body.to_string());
if let Some(csrf) = csrf {
req = req.header("x-csrf-token", csrf);
}
async move { req.send().await.unwrap() }
};
let gut = json!({"model": "sprecher", "input": "Hallo", "voice": "Ryan"});
let resp = sprechen(cookie.clone(), Some(csrf.clone()), gut.clone()).await;
assert_eq!(resp.status(), 200);
assert_eq!(resp.headers()[CONTENT_TYPE], "audio/wav");
// Die Attrappe gibt zurück, was sie gesehen hat (die Umschreibung des Modellnamens auf den des
// Studios macht `StudioEngine::endpoint`, getestet im Adapter, nicht die FixedEngine).
assert_eq!(resp.text().await.unwrap(), "RIFF|sprecher|Hallo");
// Ohne Token 403, ohne Sitzung 401, ein Chatmodell ist kein Sprachmodell.
assert_eq!(
sprechen(cookie.clone(), None, gut.clone()).await.status(),
403
);
assert_eq!(
sprechen("nexus_ui=falsch".to_string(), Some(csrf.clone()), gut)
.await
.status(),
401
);
let chatmodell = json!({"model": "bonsai", "input": "Hallo"});
assert_eq!(
sprechen(cookie.clone(), Some(csrf.clone()), chatmodell)
.await
.status(),
404
);
let leer = json!({"model": "sprecher", "input": " "});
assert_eq!(sprechen(cookie, Some(csrf), leer).await.status(), 400);
}
#[tokio::test]
async fn playground_streamt_fuer_benutzer_und_protokolliert_nur_metadaten() {
let gw = gateway(0, false).await;