feat: Sprachausgabe über das Gateway (POST /v1/audio/speech, Adapter tts für das Qwen3-TTS Studio) (#1060)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GmHhg3Td16J38kAyDLzb39
This commit is contained in:
@ -5,6 +5,7 @@
|
||||
//! - [`OllamaEngine`]: Ollama, verwaltet (`ollama serve` als Prozess) oder angehängt
|
||||
//! (laufender Server).
|
||||
//! - [`MayaEngine`]: Project Maya (`maya.py`) als verwalteter Prozess.
|
||||
//! - [`StudioEngine`]: das Faster Qwen3-TTS Studio (Sprachausgabe) als laufender Dienst.
|
||||
//! - [`MockEngine`]: Attrappe ohne Prozesse für Scheduler- und Vertragstests.
|
||||
//!
|
||||
//! Stand M2.2: Die Weiterleitung von Anfragen (`forward`) kommt mit der API
|
||||
@ -17,6 +18,7 @@ mod maya;
|
||||
mod mock;
|
||||
mod ollama;
|
||||
mod process;
|
||||
mod studio;
|
||||
mod types;
|
||||
// Dieselbe reine Parameterdefinition wie nexus-core, ohne neue Crate-Abhängigkeit.
|
||||
#[path = "../../startparams.rs"]
|
||||
@ -29,6 +31,7 @@ pub use maya::{MayaConfig, MayaEngine};
|
||||
pub use mock::{MockConfig, MockEngine};
|
||||
pub use ollama::{OllamaConfig, OllamaEngine, OllamaMode};
|
||||
pub use process::process_exists;
|
||||
pub use studio::{StudioConfig, StudioEngine};
|
||||
pub use types::{
|
||||
AdapterError, Capabilities, DiscoveredArtifact, Endpoint, EngineInfo, Health, InstanceHandle,
|
||||
Mode, ProfileSpec, Protocol, Result, StartInfo, Usage,
|
||||
|
||||
@ -349,6 +349,7 @@ impl Engine for LlamaCppEngine {
|
||||
streaming: true,
|
||||
tool_calling: false,
|
||||
images: false,
|
||||
speech: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -601,6 +601,7 @@ impl Engine for MayaEngine {
|
||||
streaming: true,
|
||||
tool_calling: self.flavor == Flavor::Strata,
|
||||
images: false,
|
||||
speech: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,6 +86,7 @@ impl Engine for MockEngine {
|
||||
streaming: true,
|
||||
tool_calling: false,
|
||||
images: false,
|
||||
speech: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -478,6 +478,7 @@ impl Engine for OllamaEngine {
|
||||
streaming: true,
|
||||
tool_calling: false,
|
||||
images: false,
|
||||
speech: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
323
crates/nexus-adapter/src/studio.rs
Normal file
323
crates/nexus-adapter/src/studio.rs
Normal file
@ -0,0 +1,323 @@
|
||||
//! Adapter für das Faster Qwen3-TTS Studio (Sprachausgabe), angehängt an einen
|
||||
//! **laufenden** Dienst (Modus External).
|
||||
//!
|
||||
//! Das Studio (im Container, Port 8862 auf srv04) bietet `POST /v1/audio/speech`
|
||||
//! im OpenAI-Format. Es lädt und entlädt seine Modelle selbst, auf Anfrage; das
|
||||
//! Gateway steuert das nicht. Eine Gateway-„Instanz“ ist deshalb nur die
|
||||
//! Zusage „der Dienst ist erreichbar, dieses Modell wird angefragt“. `start`
|
||||
//! prüft die Erreichbarkeit (`GET /studio/status`), `stop` vergisst die Instanz.
|
||||
//! Das Feld `model` der Anfrage wird auf den Modellnamen des Studios umgeschrieben
|
||||
//! (zum Beispiel `Qwen/Qwen3-TTS-12Hz-1.7B-Base`), der als Pfad im Profil steht.
|
||||
//!
|
||||
//! Gelesen und am 17.11.2026 gegen das Studio auf srv04 geprüft: `/studio/status`,
|
||||
//! `/v1/models` (zeigt auch nicht installierte Modelle) und `POST /v1/audio/speech`.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
use std::time::Duration;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::engine::Engine;
|
||||
use crate::types::{
|
||||
AdapterError, Capabilities, DiscoveredArtifact, Endpoint, EngineInfo, Health, InstanceHandle,
|
||||
Mode, ProfileSpec, Protocol, Result, StartInfo, Usage,
|
||||
};
|
||||
|
||||
/// Konfiguration (Abschnitt `[tts]`). Enthält keine Geheimnisse.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||
#[serde(default, deny_unknown_fields)]
|
||||
pub struct StudioConfig {
|
||||
/// Adresse des laufenden Studios.
|
||||
pub base_url: String,
|
||||
/// Wie lange die Erreichbarkeitsprüfung beim Start höchstens dauert.
|
||||
pub ready_timeout_secs: u64,
|
||||
}
|
||||
|
||||
impl Default for StudioConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
base_url: "http://127.0.0.1:8862".to_string(),
|
||||
ready_timeout_secs: 15,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct StudioEngine {
|
||||
config: StudioConfig,
|
||||
http: reqwest::Client,
|
||||
next_id: AtomicU64,
|
||||
/// Instanz-ID -> Modellname im Studio.
|
||||
models: Mutex<HashMap<u64, String>>,
|
||||
}
|
||||
|
||||
impl StudioEngine {
|
||||
pub fn new(config: StudioConfig) -> Self {
|
||||
Self {
|
||||
config,
|
||||
http: reqwest::Client::builder()
|
||||
.connect_timeout(Duration::from_secs(3))
|
||||
.build()
|
||||
.expect("HTTP-Client konnte nicht gebaut werden"),
|
||||
next_id: AtomicU64::new(1),
|
||||
models: Mutex::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
|
||||
fn base(&self) -> &str {
|
||||
self.config.base_url.trim_end_matches('/')
|
||||
}
|
||||
|
||||
fn models(&self) -> std::sync::MutexGuard<'_, HashMap<u64, String>> {
|
||||
self.models.lock().unwrap_or_else(|e| e.into_inner())
|
||||
}
|
||||
|
||||
fn port(&self) -> u16 {
|
||||
self.base()
|
||||
.rsplit(':')
|
||||
.next()
|
||||
.and_then(|p| p.parse().ok())
|
||||
.unwrap_or(80)
|
||||
}
|
||||
|
||||
async fn reachable(&self, timeout: Duration) -> bool {
|
||||
matches!(
|
||||
self.http
|
||||
.get(format!("{}/studio/status", self.base()))
|
||||
.timeout(timeout)
|
||||
.send()
|
||||
.await,
|
||||
Ok(r) if r.status().is_success()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Aus der Antwort von `/v1/models`: Modellnamen des Studios als Vorschläge.
|
||||
fn models_from(json: &Value) -> Vec<DiscoveredArtifact> {
|
||||
json["data"]
|
||||
.as_array()
|
||||
.map(|list| {
|
||||
list.iter()
|
||||
.filter_map(|m| m["id"].as_str())
|
||||
.map(|id| DiscoveredArtifact {
|
||||
name: id.rsplit('/').next().unwrap_or(id).to_string(),
|
||||
path: id.into(),
|
||||
quantization: None,
|
||||
size_bytes: 0,
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Engine for StudioEngine {
|
||||
fn describe(&self) -> EngineInfo {
|
||||
EngineInfo {
|
||||
name: "tts".to_string(),
|
||||
mode: Mode::External,
|
||||
// Gemessen am 17.11.2026: Sprachausgabe über `POST /v1/audio/speech`.
|
||||
capabilities: Capabilities {
|
||||
speech: true,
|
||||
..Capabilities::default()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn start_info(&self) -> StartInfo {
|
||||
StartInfo {
|
||||
executable: None,
|
||||
command:
|
||||
"läuft extern (Faster Qwen3-TTS Studio, Container); das Gateway startet nichts"
|
||||
.to_string(),
|
||||
env: Vec::new(),
|
||||
details: vec![("Adresse".to_string(), self.config.base_url.clone())],
|
||||
}
|
||||
}
|
||||
|
||||
async fn discover(&self) -> Result<Vec<DiscoveredArtifact>> {
|
||||
let resp = self
|
||||
.http
|
||||
.get(format!("{}/v1/models", self.base()))
|
||||
.timeout(Duration::from_secs(self.config.ready_timeout_secs))
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| AdapterError::Spawn(format!("Studio nicht erreichbar: {e}")))?;
|
||||
let bytes = resp
|
||||
.bytes()
|
||||
.await
|
||||
.map_err(|e| AdapterError::Spawn(format!("Studio-Antwort nicht lesbar: {e}")))?;
|
||||
let json: Value = serde_json::from_slice(&bytes)
|
||||
.map_err(|e| AdapterError::Spawn(format!("Studio-Antwort kein JSON: {e}")))?;
|
||||
Ok(models_from(&json))
|
||||
}
|
||||
|
||||
async fn start(&self, profile: &ProfileSpec) -> Result<InstanceHandle> {
|
||||
let model = profile.model_path.to_string_lossy().trim().to_string();
|
||||
if model.is_empty() {
|
||||
return Err(AdapterError::InvalidProfile(
|
||||
"kein Modellname des Studios angegeben".to_string(),
|
||||
));
|
||||
}
|
||||
let timeout = Duration::from_secs(self.config.ready_timeout_secs);
|
||||
if !self.reachable(timeout).await {
|
||||
return Err(AdapterError::NotReady {
|
||||
seconds: self.config.ready_timeout_secs,
|
||||
log_tail: format!("{} antwortet nicht", self.base()),
|
||||
});
|
||||
}
|
||||
let id = self.next_id.fetch_add(1, Ordering::SeqCst);
|
||||
self.models().insert(id, model);
|
||||
Ok(InstanceHandle {
|
||||
id,
|
||||
pid: None,
|
||||
port: self.port(),
|
||||
})
|
||||
}
|
||||
|
||||
async fn stop(&self, instance: &InstanceHandle, _grace: Duration) -> Result<()> {
|
||||
self.models().remove(&instance.id);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn health(&self, instance: &InstanceHandle) -> Health {
|
||||
if !self.models().contains_key(&instance.id) {
|
||||
return Health::Gone;
|
||||
}
|
||||
if self.reachable(Duration::from_secs(5)).await {
|
||||
Health::Ready
|
||||
} else {
|
||||
Health::Unhealthy("keine Antwort".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
fn endpoint(&self, instance: &InstanceHandle) -> Endpoint {
|
||||
Endpoint {
|
||||
base_url: self.base().to_string(),
|
||||
protocol: Protocol::OpenAi,
|
||||
upstream_model: self.models().get(&instance.id).cloned(),
|
||||
}
|
||||
}
|
||||
|
||||
async fn measure(&self, _instance: &InstanceHandle) -> Usage {
|
||||
Usage::default()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::path::PathBuf;
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::net::TcpListener;
|
||||
|
||||
/// Minimaler HTTP-Server: antwortet je Pfad mit fester JSON-Antwort.
|
||||
async fn fake_studio() -> u16 {
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||
let port = listener.local_addr().unwrap().port();
|
||||
tokio::spawn(async move {
|
||||
loop {
|
||||
let Ok((mut s, _)) = listener.accept().await else {
|
||||
return;
|
||||
};
|
||||
tokio::spawn(async move {
|
||||
let mut buf = [0u8; 2048];
|
||||
let n = s.read(&mut buf).await.unwrap_or(0);
|
||||
let head = String::from_utf8_lossy(&buf[..n]).to_string();
|
||||
let body = if head.starts_with("GET /studio/status") {
|
||||
r#"{"state":"idle"}"#
|
||||
} else if head.starts_with("GET /v1/models") {
|
||||
r#"{"data":[{"id":"Qwen/Qwen3-TTS-12Hz-1.7B-Base"},{"id":"Qwen/Qwen3-TTS-12Hz-1.7B-CustomVoice"}]}"#
|
||||
} else {
|
||||
r#"{}"#
|
||||
};
|
||||
let resp = format!(
|
||||
"HTTP/1.1 200 OK\r\ncontent-type: application/json\r\ncontent-length: {}\r\nconnection: close\r\n\r\n{body}",
|
||||
body.len()
|
||||
);
|
||||
let _ = s.write_all(resp.as_bytes()).await;
|
||||
});
|
||||
}
|
||||
});
|
||||
port
|
||||
}
|
||||
|
||||
fn profile(model: &str) -> ProfileSpec {
|
||||
ProfileSpec {
|
||||
start_parameters: Default::default(),
|
||||
model_alias: "tts-test".to_string(),
|
||||
model_path: PathBuf::from(model),
|
||||
gpus: vec![0],
|
||||
context: None,
|
||||
extra_args: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn engine(port: u16) -> StudioEngine {
|
||||
StudioEngine::new(StudioConfig {
|
||||
base_url: format!("http://127.0.0.1:{port}/"),
|
||||
ready_timeout_secs: 3,
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn modellliste_wird_zu_vorschlaegen_mit_kurzem_namen() {
|
||||
let json: Value = serde_json::from_str(
|
||||
r#"{"data":[{"id":"Qwen/Qwen3-TTS-12Hz-1.7B-Base"},{"object":"x"}]}"#,
|
||||
)
|
||||
.unwrap();
|
||||
let found = models_from(&json);
|
||||
assert_eq!(found.len(), 1);
|
||||
assert_eq!(found[0].name, "Qwen3-TTS-12Hz-1.7B-Base");
|
||||
assert_eq!(
|
||||
found[0].path,
|
||||
PathBuf::from("Qwen/Qwen3-TTS-12Hz-1.7B-Base")
|
||||
);
|
||||
assert!(models_from(&Value::Null).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn beschreibt_nur_sprachausgabe() {
|
||||
let info = engine(1).describe();
|
||||
assert_eq!(info.name, "tts");
|
||||
assert!(info.capabilities.speech && !info.capabilities.chat);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn start_prueft_erreichbarkeit_und_endpunkt_nennt_das_studio_modell() {
|
||||
let port = fake_studio().await;
|
||||
let e = engine(port);
|
||||
let handle = e
|
||||
.start(&profile("Qwen/Qwen3-TTS-12Hz-1.7B-Base"))
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(handle.port, port);
|
||||
assert!(matches!(e.health(&handle).await, Health::Ready));
|
||||
let ep = e.endpoint(&handle);
|
||||
assert_eq!(ep.base_url, format!("http://127.0.0.1:{port}"));
|
||||
assert_eq!(
|
||||
ep.upstream_model.as_deref(),
|
||||
Some("Qwen/Qwen3-TTS-12Hz-1.7B-Base")
|
||||
);
|
||||
assert_eq!(e.discover().await.unwrap().len(), 2);
|
||||
e.stop(&handle, Duration::from_secs(1)).await.unwrap();
|
||||
assert!(matches!(e.health(&handle).await, Health::Gone));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn nicht_erreichbar_und_leerer_modellname_scheitern() {
|
||||
// Port 1 ist nicht belegt.
|
||||
let e = engine(1);
|
||||
assert!(matches!(
|
||||
e.start(&profile("x")).await,
|
||||
Err(AdapterError::NotReady { .. })
|
||||
));
|
||||
assert!(matches!(
|
||||
e.start(&profile(" ")).await,
|
||||
Err(AdapterError::InvalidProfile(_))
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -28,6 +28,8 @@ pub struct Capabilities {
|
||||
pub streaming: bool,
|
||||
pub tool_calling: bool,
|
||||
pub images: bool,
|
||||
/// Sprachausgabe (`POST /v1/audio/speech`).
|
||||
pub speech: bool,
|
||||
}
|
||||
|
||||
/// Wie das Gateway eine Engine startet, zum Anzeigen in der Oberfläche. Enthält
|
||||
|
||||
@ -37,6 +37,31 @@ pub async fn completions(
|
||||
forward(state, &key, priority, slot, correlation, started, body).await
|
||||
}
|
||||
|
||||
/// `POST /v1/audio/speech`: Sprachausgabe. Derselbe Weg wie beim Chat (Rechte, Zuteilung,
|
||||
/// Durchreichen, Protokoll); die Antwort ist Audio, kein JSON.
|
||||
pub async fn speech(
|
||||
State(state): State<Arc<AppState>>,
|
||||
Authed(key): Authed,
|
||||
Extension(slot): Extension<AccessSlot>,
|
||||
Extension(RequestId(correlation)): Extension<RequestId>,
|
||||
Extension(StartedAt(started)): Extension<StartedAt>,
|
||||
headers: HeaderMap,
|
||||
body: Bytes,
|
||||
) -> Result<Response, ApiError> {
|
||||
let priority = requested_priority(&headers, &key)?;
|
||||
forward_to(
|
||||
"/v1/audio/speech",
|
||||
state,
|
||||
&key,
|
||||
priority,
|
||||
slot,
|
||||
correlation,
|
||||
started,
|
||||
body,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Der gemeinsame Weg einer Chat-Anfrage, für die API und den Playground der
|
||||
/// Oberfläche: Rechte prüfen, Instanz zuteilen lassen, durchreichen.
|
||||
pub(crate) async fn forward(
|
||||
@ -47,6 +72,31 @@ pub(crate) async fn forward(
|
||||
correlation: String,
|
||||
started: std::time::Instant,
|
||||
body: Bytes,
|
||||
) -> Result<Response, ApiError> {
|
||||
forward_to(
|
||||
"/v1/chat/completions",
|
||||
state,
|
||||
key,
|
||||
priority,
|
||||
slot,
|
||||
correlation,
|
||||
started,
|
||||
body,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Wie `forward`, an einen anderen Pfad der Engine (Chat oder Sprachausgabe).
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
async fn forward_to(
|
||||
path: &'static str,
|
||||
state: Arc<AppState>,
|
||||
key: &ApiKeyRecord,
|
||||
priority: Priority,
|
||||
slot: AccessSlot,
|
||||
correlation: String,
|
||||
started: std::time::Instant,
|
||||
body: Bytes,
|
||||
) -> Result<Response, ApiError> {
|
||||
let mut request: Value = serde_json::from_slice(&body)
|
||||
.map_err(|e| ApiError::bad_request(format!("Der Body ist kein gültiges JSON: {e}")))?;
|
||||
@ -96,7 +146,7 @@ pub(crate) async fn forward(
|
||||
|
||||
let upstream = state
|
||||
.http
|
||||
.post(format!("{}/v1/chat/completions", endpoint.base_url))
|
||||
.post(format!("{}{path}", endpoint.base_url))
|
||||
.header(CONTENT_TYPE, "application/json")
|
||||
.header("x-request-id", &correlation)
|
||||
.body(body)
|
||||
@ -134,7 +184,7 @@ pub(crate) async fn forward(
|
||||
.remove("reasoning_effort");
|
||||
let retry = state
|
||||
.http
|
||||
.post(format!("{}/v1/chat/completions", endpoint.base_url))
|
||||
.post(format!("{}{path}", endpoint.base_url))
|
||||
.header(CONTENT_TYPE, "application/json")
|
||||
.header("x-request-id", &correlation)
|
||||
.body(serde_json::to_vec(&request).map_err(|_| ApiError::internal())?)
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
//! OpenAI-kompatible HTTP-API und Gateway-Endpunkte (Spezifikation, Abschnitt 7).
|
||||
//!
|
||||
//! Stand M2.3: `GET /v1/models`, `GET /v1/models/{id}`,
|
||||
//! `POST /v1/chat/completions` (mit SSE-Streaming), `GET /gateway/v1/health`,
|
||||
//! `POST /v1/chat/completions` (mit SSE-Streaming), `POST /v1/audio/speech` (Sprachausgabe), `GET /gateway/v1/health`,
|
||||
//! API-Key-Authentifizierung und das OpenAI-Fehlerformat. Weitere Endpunkte
|
||||
//! (Completions, Embeddings, Bilder) und die Gateway-Verwaltung folgen später.
|
||||
//!
|
||||
@ -49,6 +49,7 @@ pub fn router(state: Arc<AppState>) -> Router {
|
||||
.route("/v1/models", get(models::list))
|
||||
.route("/v1/models/{id}", get(models::retrieve))
|
||||
.route("/v1/chat/completions", post(chat::completions))
|
||||
.route("/v1/audio/speech", post(chat::speech))
|
||||
.route("/gateway/v1/health", get(health))
|
||||
.route("/gateway/v1/metrics", get(metrics_endpoint))
|
||||
.route("/gateway/v1/status", get(status_endpoint))
|
||||
|
||||
@ -1193,7 +1193,7 @@ pre.befehl{margin:0;padding:.6rem .8rem;background:var(--bg);border:1px solid va
|
||||
.engine h2{margin:0}.chips{display:flex;flex-wrap:wrap;gap:.35rem;margin:.7rem 0 .2rem}
|
||||
.engine .zeile{gap:.5rem .7rem}
|
||||
.fsym{--k:var(--muted);width:1.7rem;height:1.7rem;box-sizing:border-box;padding:.27rem;margin-right:.3rem;vertical-align:middle;border-radius:.45rem;fill:none;stroke:var(--k);stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
|
||||
td.faehig{white-space:nowrap}.fkann{display:inline-flex;align-items:center;gap:.1rem;margin:0 .6rem .3rem 0;white-space:nowrap}.fsym.k-chat{--k:var(--info)}.fsym.k-vision{--k:var(--accent-strong)}.fsym.k-tools{--k:var(--cat-2)}.fsym.k-embed{--k:var(--ok)}.fsym.k-stream{--k:var(--cat-1)}.fsym.k-completion{--k:var(--cat-3)}
|
||||
td.faehig{white-space:nowrap}.fkann{display:inline-flex;align-items:center;gap:.1rem;margin:0 .6rem .3rem 0;white-space:nowrap}.fsym.k-chat{--k:var(--info)}.fsym.k-vision{--k:var(--accent-strong)}.fsym.k-tools{--k:var(--cat-2)}.fsym.k-embed{--k:var(--ok)}.fsym.k-stream{--k:var(--cat-1)}.fsym.k-completion{--k:var(--cat-3)}.fsym.k-speech{--k:var(--warn)}
|
||||
.fsym.gemeldet,.fsym.datei{background:color-mix(in srgb,var(--k) 22%,transparent);border:1px solid color-mix(in srgb,var(--k) 55%,transparent)}
|
||||
.fsym.engine{background:transparent;border:1px dashed color-mix(in srgb,var(--k) 55%,transparent);opacity:.75}
|
||||
footer label{display:inline-flex;gap:.35rem;align-items:center}footer select{padding:.15rem .4rem;font-size:.8rem}
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
//! ein `mmproj` neben der Modelldatei). Ein Test am Modell selbst gibt es noch nicht; bis dahin
|
||||
//! steht in keinem Symbol „geprüft“.
|
||||
//!
|
||||
//! Je Modell nur, was vom Modell abhängt (Bilder, Werkzeuge, Embeddings). Chat, Streaming und
|
||||
//! Je Modell nur, was vom Modell abhängt (Bilder, Werkzeuge, Embeddings, Sprachausgabe). Chat, Streaming und
|
||||
//! Completions sind Fähigkeiten der Engine und stehen auf der Seite „Engines“.
|
||||
//!
|
||||
//! Darstellung: je Fähigkeit eine eigene Farbe (Klasse `k-…`); gefüllte Kachel = aus den Dateien
|
||||
@ -22,7 +22,7 @@ pub(super) enum Herkunft {
|
||||
Datei,
|
||||
}
|
||||
|
||||
/// Symbole in fester Reihenfolge: Chat, Bilder (Vision), Werkzeuge, Embeddings, Streaming, Completions.
|
||||
/// Symbole in fester Reihenfolge: Chat, Bilder (Vision), Werkzeuge, Embeddings, Streaming, Completions, Sprachausgabe.
|
||||
pub(super) fn capability_icons(caps: &Capabilities) -> Vec<&'static str> {
|
||||
let mut icons = Vec::new();
|
||||
if caps.chat {
|
||||
@ -43,6 +43,9 @@ pub(super) fn capability_icons(caps: &Capabilities) -> Vec<&'static str> {
|
||||
if caps.completions {
|
||||
icons.push("completion");
|
||||
}
|
||||
if caps.speech {
|
||||
icons.push("speech");
|
||||
}
|
||||
icons
|
||||
}
|
||||
|
||||
@ -104,7 +107,7 @@ pub(super) fn symbole(
|
||||
let engine_icons = caps.map(capability_icons).unwrap_or_default();
|
||||
// Chat, Streaming und Completions hängen an der Engine, nicht am Modell: Sie stehen auf der
|
||||
// Seite „Engines“ (`engine_faehigkeiten`), nicht in der Spalte „Kann“ je Modell.
|
||||
for key in ["vision", "tools", "embed"] {
|
||||
for key in ["vision", "tools", "embed", "speech"] {
|
||||
if datei.contains(&key) {
|
||||
out.push((key, Herkunft::Datei));
|
||||
} else if engine_icons.contains(&key) {
|
||||
@ -138,6 +141,10 @@ fn svg(key: &str) -> &'static str {
|
||||
"stream" => {
|
||||
"<path d=\"M2 10v3\"/><path d=\"M6 6v11\"/><path d=\"M10 3v18\"/><path d=\"M14 8v7\"/><path d=\"M18 5v13\"/><path d=\"M22 10v3\"/>"
|
||||
}
|
||||
// volume-2
|
||||
"speech" => {
|
||||
"<path d=\"M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z\"/><path d=\"M16 9a5 5 0 0 1 0 6\"/><path d=\"M19.364 18.364a9 9 0 0 0 0-12.728\"/>"
|
||||
}
|
||||
// braces
|
||||
_ => {
|
||||
"<path d=\"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1\"/><path d=\"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1\"/>"
|
||||
@ -152,6 +159,7 @@ fn titel(key: &str) -> &'static str {
|
||||
"tools" => "Werkzeuge aufrufen (Tool Calling)",
|
||||
"embed" => "Embeddings",
|
||||
"stream" => "Streaming",
|
||||
"speech" => "Sprachausgabe",
|
||||
_ => "Completions",
|
||||
}
|
||||
}
|
||||
@ -217,9 +225,23 @@ mod tests {
|
||||
streaming: stream,
|
||||
tool_calling: tools,
|
||||
images,
|
||||
speech: false,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sprachausgabe_ist_ein_eigenes_symbol_je_modell() {
|
||||
let c = Capabilities {
|
||||
speech: true,
|
||||
..Capabilities::default()
|
||||
};
|
||||
assert_eq!(capability_icons(&c), ["speech"]);
|
||||
let s = symbole(Some(&c), "tts", "Qwen/Qwen3-TTS-12Hz-1.7B-Base");
|
||||
assert_eq!(s, vec![("speech", Herkunft::Engine)]);
|
||||
assert!(zelle(&s).contains("k-speech") && zelle(&s).contains("Sprachausgabe"));
|
||||
assert!(engine_faehigkeiten(&c).contains("Sprachausgabe"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn icons_in_fester_reihenfolge() {
|
||||
assert!(capability_icons(&caps(false, false, false, false, false, false)).is_empty());
|
||||
|
||||
@ -178,7 +178,20 @@ async fn fake_backend() -> u16 {
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
// Sprachausgabe: liefert ein winziges „Audio“ und gibt die gesehenen Felder im Kopf zurück.
|
||||
async fn speech(body: Bytes) -> Response {
|
||||
let req: Value = serde_json::from_slice(&body).unwrap();
|
||||
Response::builder()
|
||||
.header(CONTENT_TYPE, "audio/wav")
|
||||
.body(Body::from(format!(
|
||||
"RIFF|{}|{}",
|
||||
req["model"].as_str().unwrap_or(""),
|
||||
req["input"].as_str().unwrap_or("")
|
||||
)))
|
||||
.unwrap()
|
||||
}
|
||||
serve(Router::new()
|
||||
.route("/v1/audio/speech", post(speech))
|
||||
.route("/", axum::routing::get(|| async { axum::response::Html("<html><script src='/app.js'></script>ENGINE-INHALT-NICHT-AUSLIEFERN</html>") }))
|
||||
.route("/v1/chat/completions", post(chat))).await
|
||||
}
|
||||
@ -496,6 +509,37 @@ async fn chat_ohne_streaming_startet_die_instanz_und_reicht_die_antwort_durch()
|
||||
assert_eq!(gw.engine.starts.load(Ordering::SeqCst), 1);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn sprachausgabe_reicht_audio_durch_und_verlangt_key_und_modell() {
|
||||
let gw = gateway(0, false).await;
|
||||
let body = json!({"model": "bonsai", "input": "Hallo", "voice": "Vivian"}).to_string();
|
||||
let post = |key: Option<&str>, body: String| {
|
||||
let mut req = gw
|
||||
.client
|
||||
.post(format!("{}/v1/audio/speech", gw.base))
|
||||
.header(CONTENT_TYPE, "application/json")
|
||||
.body(body);
|
||||
if let Some(k) = key {
|
||||
req = req.bearer_auth(k);
|
||||
}
|
||||
async move { req.send().await.unwrap() }
|
||||
};
|
||||
let resp = post(Some(&gw.key), body.clone()).await;
|
||||
assert_eq!(resp.status(), 200);
|
||||
assert_eq!(resp.headers()[CONTENT_TYPE], "audio/wav");
|
||||
// Die Attrappe gibt zurück, was sie gesehen hat: Modellname und Text unverändert.
|
||||
assert_eq!(resp.text().await.unwrap(), "RIFF|bonsai|Hallo");
|
||||
assert_eq!(gw.engine.starts.load(Ordering::SeqCst), 1);
|
||||
|
||||
assert_eq!(post(None, body.clone()).await.status(), 401);
|
||||
let unbekannt = json!({"model": "gibt-es-nicht", "input": "x", "voice": "v"}).to_string();
|
||||
assert_eq!(post(Some(&gw.key), unbekannt).await.status(), 404);
|
||||
assert_eq!(
|
||||
post(Some(&gw.key), "kein json".to_string()).await.status(),
|
||||
400
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn streaming_wird_stueckweise_durchgereicht_und_nicht_gepuffert() {
|
||||
let gw = gateway(0, false).await;
|
||||
|
||||
@ -47,6 +47,8 @@ pub struct Config {
|
||||
pub maya: toml::Table,
|
||||
/// Rohe Einstellungen des Strata-Adapters (Abschnitt `[strata]`).
|
||||
pub strata: toml::Table,
|
||||
/// Rohe Einstellungen des Sprachausgabe-Adapters (Abschnitt `[tts]`).
|
||||
pub tts: toml::Table,
|
||||
}
|
||||
|
||||
/// Einstellungen des Schedulers (Entscheidungen #1051 bis #1056).
|
||||
@ -104,6 +106,7 @@ impl Default for Config {
|
||||
ollama: toml::Table::new(),
|
||||
maya: toml::Table::new(),
|
||||
strata: toml::Table::new(),
|
||||
tts: toml::Table::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,6 +15,8 @@ pub const OLLAMA: &str = "ollama";
|
||||
pub const MAYA: &str = "maya";
|
||||
/// Name der Engine-Zeile für Strata.
|
||||
pub const STRATA: &str = "strata";
|
||||
/// Name der Engine-Zeile für die Sprachausgabe (Faster Qwen3-TTS Studio).
|
||||
pub const TTS: &str = "tts";
|
||||
|
||||
/// Eingabe für `register_llm`: ein Sprachmodell mit einem Startprofil.
|
||||
#[derive(Debug, Clone)]
|
||||
@ -105,9 +107,10 @@ impl Store {
|
||||
&& new.engine != OLLAMA
|
||||
&& new.engine != MAYA
|
||||
&& new.engine != STRATA
|
||||
&& new.engine != TTS
|
||||
{
|
||||
return Err(Error::Db(format!(
|
||||
"unbekannte Engine \"{}\" (llama.cpp, ollama, maya oder strata)",
|
||||
"unbekannte Engine \"{}\" (llama.cpp, ollama, maya, strata oder tts)",
|
||||
new.engine
|
||||
)));
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
use std::path::PathBuf;
|
||||
use std::process::ExitCode;
|
||||
|
||||
use nexus_adapter::{Engine, LlamaCppEngine, MayaEngine, OllamaEngine};
|
||||
use nexus_adapter::{Engine, LlamaCppEngine, MayaEngine, OllamaEngine, StudioEngine};
|
||||
use nexus_core::Priority;
|
||||
use nexus_store::{NewLlm, Rights};
|
||||
|
||||
@ -281,6 +281,7 @@ fn model_add(args: &[String]) -> Result<(), String> {
|
||||
"tag",
|
||||
"maya-config",
|
||||
"strata-config",
|
||||
"tts-model",
|
||||
"gpus",
|
||||
"context",
|
||||
"vram-mb",
|
||||
@ -321,9 +322,12 @@ fn model_add(args: &[String]) -> Result<(), String> {
|
||||
}
|
||||
(path, None)
|
||||
}
|
||||
// Sprachausgabe: der Modellname im laufenden Studio (zum Beispiel
|
||||
// `Qwen/Qwen3-TTS-12Hz-1.7B-Base`); das Studio lädt ihn selbst.
|
||||
"tts" => (PathBuf::from(flags.require("tts-model")?), None),
|
||||
other => {
|
||||
return Err(format!(
|
||||
"Unbekannte Engine \"{other}\" (llama.cpp, ollama, maya oder strata)."
|
||||
"Unbekannte Engine \"{other}\" (llama.cpp, ollama, maya, strata oder tts)."
|
||||
));
|
||||
}
|
||||
};
|
||||
@ -517,9 +521,14 @@ async fn model_discover(args: &[String]) -> Result<(), String> {
|
||||
.discover()
|
||||
.await
|
||||
}
|
||||
"tts" => {
|
||||
StudioEngine::new(crate::serve::tts_config(&config)?)
|
||||
.discover()
|
||||
.await
|
||||
}
|
||||
other => {
|
||||
return Err(format!(
|
||||
"Unbekannte Engine \"{other}\" (llama.cpp, ollama, maya oder strata)."
|
||||
"Unbekannte Engine \"{other}\" (llama.cpp, ollama, maya, strata oder tts)."
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -544,6 +553,8 @@ async fn model_discover(args: &[String]) -> Result<(), String> {
|
||||
"--engine maya --maya-config <pfad>"
|
||||
} else if engine == "strata" {
|
||||
"--engine strata --strata-config <pfad>"
|
||||
} else if engine == "tts" {
|
||||
"--engine tts --tts-model <Modellname im Studio>"
|
||||
} else {
|
||||
"--path <pfad>"
|
||||
}
|
||||
|
||||
@ -28,8 +28,9 @@ Aufruf:
|
||||
nexus model add --name N --engine ollama --tag MODELLNAME [--gpus 0] [--disabled]
|
||||
nexus model add --name N --engine maya --maya-config PFAD.json [--gpus 0,1] [--disabled]
|
||||
nexus model add --name N --engine strata --strata-config PFAD.json [--gpus 0,1] [--disabled]
|
||||
nexus model add --name N --engine tts --tts-model QWEN-MODELL [--gpus 0] [--vram-mb N] [--disabled] (Sprachausgabe, laufendes Studio)
|
||||
nexus model set --name N [--vram-mb N] [--idle-min MINUTEN (0 = nie) | --idle-default]
|
||||
nexus model list | enable --name N | disable --name N | remove --name N (nur gesperrte Modelle) | discover [--engine llama.cpp|ollama|maya|strata]
|
||||
nexus model list | enable --name N | disable --name N | remove --name N (nur gesperrte Modelle) | discover [--engine llama.cpp|ollama|maya|strata|tts]
|
||||
nexus diag [--out DATEI.tar.gz] [--ohne-engine-logs] Diagnose-Archiv ohne Prompts und Keys
|
||||
nexus backup [--out DATEI.db] Kopie der Datenbank (ohne sie zu migrieren; auch bei laufendem Gateway)
|
||||
nexus help Diese Hilfe
|
||||
|
||||
@ -8,6 +8,7 @@ use std::time::Duration;
|
||||
|
||||
use nexus_adapter::{
|
||||
Engine, LlamaCppConfig, LlamaCppEngine, MayaConfig, MayaEngine, OllamaConfig, OllamaEngine,
|
||||
StudioConfig, StudioEngine,
|
||||
};
|
||||
use nexus_api::{AppState, Runtime, RuntimeOptions, SchedulerSettings};
|
||||
use nexus_core::Config;
|
||||
@ -30,6 +31,15 @@ pub fn llama_config(config: &Config) -> Result<LlamaCppConfig, String> {
|
||||
.map_err(|e| format!("Konfiguration [llama_cpp]: {e}"))
|
||||
}
|
||||
|
||||
/// Liest den Abschnitt `[tts]` (Sprachausgabe, Faster Qwen3-TTS Studio).
|
||||
pub fn tts_config(config: &Config) -> Result<StudioConfig, String> {
|
||||
config
|
||||
.tts
|
||||
.clone()
|
||||
.try_into::<StudioConfig>()
|
||||
.map_err(|e| format!("Konfiguration [tts]: {e}"))
|
||||
}
|
||||
|
||||
/// Liest den Abschnitt `[ollama]`; ohne eigenen `log_dir` landen die Logs im
|
||||
/// Datenverzeichnis.
|
||||
pub fn ollama_config(config: &Config) -> Result<OllamaConfig, String> {
|
||||
@ -148,6 +158,10 @@ async fn run(args: &[String]) -> Result<(), String> {
|
||||
"strata".to_string(),
|
||||
Arc::new(MayaEngine::strata(strata_config(&config)?)),
|
||||
);
|
||||
engines.insert(
|
||||
"tts".to_string(),
|
||||
Arc::new(StudioEngine::new(tts_config(&config)?)),
|
||||
);
|
||||
let state = AppState::new(
|
||||
store,
|
||||
Runtime::with_options(engines, runtime_options(&config)),
|
||||
|
||||
Reference in New Issue
Block a user