kpn load: laitteiston VRAM/RAM tarkistus, liian isot mallit merkitään

Hub: uusi GET /api/v1/hardware palauttaa natiivisolmun GPU/RAM-tiedot.
Frontend: kpn load hakee laitteistotiedon ja näyttää mallit joihin
laite riittää. Liian isot mallit näkyvät yliviivattuina + varoitus.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-07 07:08:34 +03:00
parent 34ef19472a
commit 216b95d15c
2 changed files with 61 additions and 11 deletions

View File

@@ -385,6 +385,7 @@ async fn main() {
.route("/api/stats", get(api_stats))
.route("/api/v1/chat/completions", axum::routing::post(api_chat_completions))
.route("/api/v1/model", axum::routing::post(api_change_model))
.route("/api/v1/hardware", get(api_hardware))
.route("/admin", get(admin_page))
.nest_service("/", {
let static_dir = std::env::var("STATIC_DIR").unwrap_or_else(|_| "../static".to_string());
@@ -959,6 +960,33 @@ struct ChatCompletionResponse {
tokens_generated: u64,
}
async fn api_hardware(
axum::extract::State(state): axum::extract::State<Arc<AppState>>,
) -> axum::response::Response {
// Etsitään natiivisolmun GPU-tiedot sessiosta
let sessions = state.db.get_sessions(50);
let native = sessions.iter().find(|s| {
s.get("node_type").and_then(|v| v.as_str()) == Some("native")
});
let (vram_mb, gpu_name, ram_mb) = if let Some(s) = native {
let gpus = s.get("gpus").and_then(|v| v.as_array());
let gpu = gpus.and_then(|g| g.first());
let vram = gpu.and_then(|g| g.get("vram_total_mb")).and_then(|v| v.as_u64()).unwrap_or(0);
let name = gpu.and_then(|g| g.get("name")).and_then(|v| v.as_str()).unwrap_or("?");
let ram = s.get("system").and_then(|v| v.get("ram_total_mb")).and_then(|v| v.as_u64()).unwrap_or(0);
(vram, name.to_string(), ram)
} else {
(0, "ei natiivisolmua".to_string(), 0)
};
axum::Json(serde_json::json!({
"gpu_name": gpu_name,
"vram_mb": vram_mb,
"ram_mb": ram_mb,
})).into_response()
}
async fn api_change_model(
axum::extract::State(state): axum::extract::State<Arc<AppState>>,
axum::Json(payload): axum::Json<serde_json::Value>,