kpn load: Ollama-mallin vaihto lennossa (0.5b → 32b)

- Hub: uusi POST /api/v1/model endpoint, broadcastaa change_model
- Native node: kuuntelee change_model, kutsuu Ollaman pull + vaihtaa mallin
- Frontend: kpn load näyttää 5 mallia, numero vaihtaa Ollaman mallin
- Selain-WASM pysyy 0.5B:nä (kpn load 1)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-07 07:05:57 +03:00
parent 54a5af96c7
commit 34ef19472a
4 changed files with 95 additions and 19 deletions

View File

@@ -384,6 +384,7 @@ async fn main() {
.route("/api/pairs", get(api_pairs))
.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("/admin", get(admin_page))
.nest_service("/", {
let static_dir = std::env::var("STATIC_DIR").unwrap_or_else(|_| "../static".to_string());
@@ -958,6 +959,20 @@ struct ChatCompletionResponse {
tokens_generated: u64,
}
async fn api_change_model(
axum::extract::State(state): axum::extract::State<Arc<AppState>>,
axum::Json(payload): axum::Json<serde_json::Value>,
) -> axum::response::Response {
let model = payload.get("model").and_then(|v| v.as_str()).unwrap_or("");
if model.is_empty() {
return (axum::http::StatusCode::BAD_REQUEST, "model puuttuu").into_response();
}
tracing::info!("Mallin vaihto: {}", model);
let msg = serde_json::json!({ "type": "change_model", "model": model });
let _ = state.stats_tx.send(msg.to_string());
axum::Json(serde_json::json!({ "status": "ok", "model": model })).into_response()
}
async fn api_chat_completions(
axum::extract::State(state): axum::extract::State<Arc<AppState>>,
ConnectInfo(addr): ConnectInfo<SocketAddr>,