fix(tts): nicht installierte Sprachmodelle nicht registrieren und nicht anbieten (#1114)
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GmHhg5YdSXUmKzjHCaEWQp
This commit is contained in:
@ -129,6 +129,16 @@ impl ApiError {
|
||||
)
|
||||
}
|
||||
|
||||
/// Das Sprachmodell ist im Studio nicht installiert (Engine `tts`).
|
||||
pub fn speech_model_not_installed() -> Self {
|
||||
Self::new(
|
||||
StatusCode::NOT_FOUND,
|
||||
"invalid_request_error",
|
||||
"model_not_installed",
|
||||
"Dieses Sprachmodell ist im Studio nicht installiert.",
|
||||
)
|
||||
}
|
||||
|
||||
pub fn internal() -> Self {
|
||||
Self::new(
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
|
||||
@ -399,6 +399,14 @@ impl Runtime {
|
||||
|
||||
/// Die angeschlossenen Engines mit Fähigkeiten und Startkommando, nach Namen
|
||||
/// sortiert (für die Oberfläche).
|
||||
/// Ist das Modell auf diesem Rechner installiert? Unbekannte Engines gelten als installiert.
|
||||
pub fn model_installed(&self, engine: &str, model: &str) -> bool {
|
||||
self.shared
|
||||
.engines
|
||||
.get(engine)
|
||||
.is_none_or(|e| e.installed(model))
|
||||
}
|
||||
|
||||
/// Stimmen der Sprachausgabe einer Engine (leer, wenn es keine gibt oder sie nicht antwortet).
|
||||
pub async fn engine_voices(&self, name: &str) -> Vec<nexus_adapter::Voice> {
|
||||
match self.shared.engines.get(name) {
|
||||
|
||||
@ -561,6 +561,10 @@ pub(crate) fn notice(query: Option<&str>) -> String {
|
||||
false,
|
||||
"Nicht registriert: Die Suche findet dieses Modell nicht mehr. Bitte noch einmal suchen.",
|
||||
),
|
||||
"nicht_installiert" => (
|
||||
false,
|
||||
"Nicht registriert: Das Sprachmodell ist im Studio nicht installiert (Ordner fehlt).",
|
||||
),
|
||||
"suche_fehlt" => (
|
||||
false,
|
||||
"Die Suche bei der Engine ist gescheitert (siehe Log).",
|
||||
|
||||
@ -47,7 +47,11 @@ pub(super) async fn page(State(state): State<Arc<AppState>>, headers: HeaderMap)
|
||||
for m in candidates {
|
||||
let plan = state.store().start_plan(&m.name);
|
||||
match plan {
|
||||
Ok(Some(plan)) if plan.engine_name == "tts" => sprachmodelle.push(m.name),
|
||||
Ok(Some(plan)) if plan.engine_name == "tts" => {
|
||||
if speech_offered(&state.runtime, &plan.model_path.to_string_lossy()) {
|
||||
sprachmodelle.push(m.name);
|
||||
}
|
||||
}
|
||||
_ => models.push(m.name),
|
||||
}
|
||||
}
|
||||
@ -273,16 +277,17 @@ pub(super) async fn speak(
|
||||
Err(message) => return bad(message),
|
||||
};
|
||||
let model = request["model"].as_str().unwrap_or_default();
|
||||
let is_speech_model = viewer.key.rights.allows(model)
|
||||
&& matches!(
|
||||
state.store().start_plan(model),
|
||||
Ok(Some(plan)) if plan.engine_name == "tts"
|
||||
);
|
||||
if !is_speech_model {
|
||||
return super::refused(
|
||||
StatusCode::NOT_FOUND,
|
||||
"Das Sprachmodell ist nicht verfügbar.",
|
||||
);
|
||||
let plan = match state.store().start_plan(model) {
|
||||
Ok(Some(plan)) if plan.engine_name == "tts" && viewer.key.rights.allows(model) => plan,
|
||||
_ => {
|
||||
return super::refused(
|
||||
StatusCode::NOT_FOUND,
|
||||
"Das Sprachmodell ist nicht verfügbar.",
|
||||
);
|
||||
}
|
||||
};
|
||||
if !speech_offered(&state.runtime, &plan.model_path.to_string_lossy()) {
|
||||
return ApiError::speech_model_not_installed().into_response();
|
||||
}
|
||||
let Ok(bytes) = serde_json::to_vec(&request) else {
|
||||
return ApiError::internal().into_response();
|
||||
@ -304,6 +309,11 @@ pub(super) async fn speak(
|
||||
}
|
||||
}
|
||||
|
||||
/// Wird ein Sprachmodell (Engine `tts`) angeboten? Nur wenn es im Studio installiert ist.
|
||||
pub(crate) fn speech_offered(runtime: &crate::runtime::Runtime, model_path: &str) -> bool {
|
||||
runtime.model_installed("tts", model_path)
|
||||
}
|
||||
|
||||
/// Welche Stimmen zu einem Sprachmodell passen: Base-Modelle klonen (nur gespeicherte Stimmen),
|
||||
/// CustomVoice-Modelle sprechen mit den eingebauten Stimmen; sonst alle.
|
||||
pub(crate) fn voice_art(model_path: &str) -> &'static str {
|
||||
@ -330,8 +340,11 @@ pub(super) async fn voices(
|
||||
.and_then(|q| super::form_field(q.as_bytes(), "modell"))
|
||||
.unwrap_or_default();
|
||||
let plan = state.store().start_plan(&model).ok().flatten();
|
||||
let Some(plan) = plan.filter(|p| p.engine_name == "tts" && user.key.rights.allows(&model))
|
||||
else {
|
||||
let Some(plan) = plan.filter(|p| {
|
||||
p.engine_name == "tts"
|
||||
&& user.key.rights.allows(&model)
|
||||
&& speech_offered(&state.runtime, &p.model_path.to_string_lossy())
|
||||
}) else {
|
||||
return super::refused(
|
||||
StatusCode::NOT_FOUND,
|
||||
"Das Sprachmodell ist nicht verfügbar.",
|
||||
@ -977,6 +990,29 @@ mod tests {
|
||||
assert_eq!(voice_art("Qwen/Qwen3-TTS-12Hz-1.7B-VoiceDesign"), "alle");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nur_installierte_sprachmodelle_werden_angeboten() {
|
||||
use nexus_adapter::{StudioConfig, StudioEngine};
|
||||
use std::collections::HashMap;
|
||||
let dir = std::env::temp_dir().join(format!("nexus-chat-tts-{}", std::process::id()));
|
||||
std::fs::create_dir_all(dir.join("Qwen3-TTS-12Hz-1.7B-Base")).unwrap();
|
||||
let mut engines: HashMap<String, Arc<dyn nexus_adapter::Engine>> = HashMap::new();
|
||||
engines.insert(
|
||||
"tts".to_string(),
|
||||
Arc::new(StudioEngine::new(StudioConfig {
|
||||
local_models_dir: Some(dir.clone()),
|
||||
..StudioConfig::default()
|
||||
})),
|
||||
);
|
||||
let runtime = crate::runtime::Runtime::new(engines);
|
||||
assert!(speech_offered(&runtime, "Qwen/Qwen3-TTS-12Hz-1.7B-Base"));
|
||||
assert!(!speech_offered(
|
||||
&runtime,
|
||||
"Qwen/Qwen3-TTS-12Hz-0.6B-CustomVoice"
|
||||
));
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn skript_schreibt_nie_html() {
|
||||
assert!(!CHAT_JS.contains("innerHTML"));
|
||||
|
||||
@ -601,6 +601,12 @@ pub(super) async fn model_register(
|
||||
let Some(artifact) = found.into_iter().find(|a| a.name == fund) else {
|
||||
return back("/ui/engines", "nicht_gefunden");
|
||||
};
|
||||
if !state
|
||||
.runtime
|
||||
.model_installed(&engine, &artifact.path.to_string_lossy())
|
||||
{
|
||||
return back("/ui/engines", "nicht_installiert");
|
||||
}
|
||||
let new = NewLlm {
|
||||
name: name.clone(),
|
||||
engine: engine.clone(),
|
||||
|
||||
Reference in New Issue
Block a user