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