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:
@ -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"));
|
||||
|
||||
Reference in New Issue
Block a user