feat: expose measured model loading phases in overview and chat (#1095)
This commit is contained in:
@ -165,6 +165,30 @@ pub(super) async fn send(
|
||||
}
|
||||
}
|
||||
|
||||
/// Leichtgewichtiger Statusabruf: keine Health-Abfrage und kein Modellstart.
|
||||
pub(super) async fn load_status(
|
||||
State(state): State<Arc<AppState>>,
|
||||
headers: HeaderMap,
|
||||
axum::extract::RawQuery(query): axum::extract::RawQuery,
|
||||
) -> Response {
|
||||
let Some(user) = viewer(&state, &headers) else {
|
||||
return redirect("/ui/login");
|
||||
};
|
||||
let model = query
|
||||
.as_deref()
|
||||
.and_then(|q| super::form_field(q.as_bytes(), "modell"))
|
||||
.unwrap_or_default();
|
||||
if !user.key.rights.allows(&model) || !state.store().start_plan(&model).ok().flatten().is_some()
|
||||
{
|
||||
return super::refused(StatusCode::NOT_FOUND, "Das Modell ist nicht verfügbar.");
|
||||
}
|
||||
let status = state.runtime.model_load_status(&model);
|
||||
secure(Response::builder())
|
||||
.header(CONTENT_TYPE, "application/json")
|
||||
.body(Body::from(serde_json::to_vec(&status).unwrap_or_default()))
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
pub(super) async fn script() -> Response {
|
||||
secure(Response::builder())
|
||||
.header(CONTENT_TYPE, "text/javascript; charset=utf-8")
|
||||
@ -229,12 +253,35 @@ const CHAT_JS: &str = r#"(function () {
|
||||
var abbruch = new AbortController();
|
||||
laufend = abbruch;
|
||||
beschaeftigt(true);
|
||||
var phase = null;
|
||||
var modellName = modell.value;
|
||||
var statusLaeuft = false;
|
||||
function ladestand() {
|
||||
if (erstes !== null || laufend !== abbruch || statusLaeuft) { return; }
|
||||
statusLaeuft = true;
|
||||
fetch("/ui/chat/status?modell=" + encodeURIComponent(modellName), {
|
||||
credentials: "same-origin", signal: abbruch.signal
|
||||
}).then(function (r) { if (r.ok && r.headers.get("content-type").indexOf("application/json") !== -1) { return r.json(); } })
|
||||
.then(function (daten) { if (daten && laufend === abbruch) { phase = daten; } })
|
||||
.catch(function () {}).finally(function () { statusLaeuft = false; });
|
||||
}
|
||||
var phasenUhr = setInterval(ladestand, 1000);
|
||||
ladestand();
|
||||
var uhr = setInterval(function () {
|
||||
if (erstes === null) { status.textContent = "wartet auf das Modell … " + sekunden(beginn); }
|
||||
if (erstes !== null) { return; }
|
||||
var meldung = phase ? phase.phase : "wartet auf Zuteilung";
|
||||
if (phase && phase.elapsed_ms !== null) {
|
||||
meldung += " · Ladezeit " + (phase.elapsed_ms / 1000).toFixed(1).replace(".", ",") + " s";
|
||||
}
|
||||
if (phase && phase.last_load_ms !== null) {
|
||||
meldung += " · zuletzt gemessen " + (phase.last_load_ms / 1000).toFixed(1).replace(".", ",") + " s";
|
||||
}
|
||||
status.textContent = meldung + " · Anfrage " + sekunden(beginn);
|
||||
}, 200);
|
||||
|
||||
function ende(abgebrochen) {
|
||||
clearInterval(uhr);
|
||||
clearInterval(phasenUhr);
|
||||
laufend = null;
|
||||
beschaeftigt(false);
|
||||
if (gesamt) {
|
||||
|
||||
Reference in New Issue
Block a user