feat: private Personas und Modellgrundlage ergänzen

This commit is contained in:
2026-11-18 20:52:45 +01:00
parent ee65381172
commit 9a2727d003
11 changed files with 917 additions and 16 deletions

View File

@ -88,6 +88,17 @@ pub async fn embeddings(
.await
}
pub(crate) fn prepend_basis(request: &mut Value, basis: &str) -> Result<(), ApiError> {
if !basis.is_empty() {
let messages = request
.get_mut("messages")
.and_then(Value::as_array_mut)
.ok_or_else(|| ApiError::bad_request("Das Feld messages muss eine Liste sein."))?;
messages.insert(0, serde_json::json!({"role": "system", "content": basis}));
}
Ok(())
}
/// 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(
@ -245,6 +256,15 @@ async fn forward_to(
"Dieses Embedding-Modell unterstützt keinen Chat. Bitte ein Chat-Modell wählen.",
));
}
if path == "/v1/chat/completions" {
let basis = state
.store()
.model_systemprompt(&model)
.map_err(|_| ApiError::internal())?
.ok_or_else(|| ApiError::model_not_found(&model))?;
// Grundlage steht immer vor Persona und vor Nachrichten des Clients; API-Personas gibt es nicht.
prepend_basis(&mut request, &basis)?;
}
slot.lock().unwrap_or_else(|e| e.into_inner()).metric_model = Some(plan.model.clone());
let waited = std::time::Instant::now();
@ -266,7 +286,10 @@ async fn forward_to(
request["model"] = Value::String(name.clone());
Bytes::from(serde_json::to_vec(&request).map_err(|_| ApiError::internal())?)
}
None if audio_type.is_some() || path == "/v1/embeddings" => {
None if audio_type.is_some()
|| path == "/v1/embeddings"
|| path == "/v1/chat/completions" =>
{
Bytes::from(serde_json::to_vec(&request).map_err(|_| ApiError::internal())?)
}
None => body,