feat: Oberfläche neu, Modell-Adapter wählbar, Bewertung je Bereich
Die erste Fassung der Oberfläche war inhaltlich und optisch schwach. Neu: drei Reiter (Benchmark, Ergebnisse, Einstellungen). Modelle werden in den Einstellungen mit Adapter (Ollama oder OpenAI-kompatibel), URL, Modell-ID und Schlüssel-Variable angelegt, mit Verbindungstest. config.toml speichert die Liste. Bewertung absolut in Prozent: ein Wert je Bereich A bis D und eine Gesamtnote, gewichtet nach weight. Batch-Verlauf, Schritt-Ansicht, Erklärung der Bewertung. 55 Unit-Tests grün, svelte-check ohne Fehler. Im Browser mit Beispieldaten geprüft, nicht in der echten App. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -6,11 +6,15 @@ mod sandbox;
|
||||
mod store;
|
||||
mod tasks;
|
||||
|
||||
use config::{Config, Paths};
|
||||
use runner::{BatchSummary, Event, RunConfig};
|
||||
use config::{Config, ModelEntry, Paths};
|
||||
use runner::{BatchSummary, Event, ModelConn, RunConfig};
|
||||
use serde::Serialize;
|
||||
use std::collections::BTreeMap;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
use store::{RunRecord, Store};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::{Duration, Instant};
|
||||
use store::{BatchInfo, RunRecord, Store};
|
||||
use tauri::{Emitter, Manager, State};
|
||||
|
||||
pub const DB_FILE: &str = "coding-bench.sqlite";
|
||||
@ -19,6 +23,12 @@ pub const EVENT_NAME: &str = "batch-event";
|
||||
/// Aufgelöste Pfade, einmal beim Start ermittelt.
|
||||
pub struct AppPaths(pub Paths);
|
||||
|
||||
/// Die laufende Konfiguration. Die Oberfläche ändert die Modell-Liste, die Datei wird mitgeschrieben.
|
||||
pub struct ConfigState {
|
||||
pub config: Mutex<Config>,
|
||||
pub file: PathBuf,
|
||||
}
|
||||
|
||||
/// Steuerung für den laufenden Batch. Es läuft immer nur einer.
|
||||
pub struct RunState {
|
||||
/// Gesetzt, wenn der laufende Batch abbrechen soll.
|
||||
@ -27,6 +37,36 @@ pub struct RunState {
|
||||
pub running: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
/// Ein Modell für die Oberfläche, mit Hinweis, ob die Schlüssel-Variable gesetzt ist.
|
||||
#[derive(Serialize)]
|
||||
pub struct ModelInfo {
|
||||
#[serde(flatten)]
|
||||
pub entry: ModelEntry,
|
||||
pub api_key_set: bool,
|
||||
}
|
||||
|
||||
fn model_info(entry: &ModelEntry) -> ModelInfo {
|
||||
let api_key_set = !entry.api_key_env.is_empty()
|
||||
&& std::env::var(&entry.api_key_env).map_or(false, |v| !v.is_empty());
|
||||
ModelInfo { entry: entry.clone(), api_key_set }
|
||||
}
|
||||
|
||||
/// Löst einen Eintrag in eine Verbindung auf: Modell-ID und Schlüssel aus der Umgebung.
|
||||
fn conn_of(entry: &ModelEntry) -> ModelConn {
|
||||
let api_key = if entry.api_key_env.is_empty() {
|
||||
None
|
||||
} else {
|
||||
std::env::var(&entry.api_key_env).ok().filter(|k| !k.is_empty())
|
||||
};
|
||||
ModelConn {
|
||||
name: entry.name.clone(),
|
||||
adapter: entry.adapter.clone(),
|
||||
url: entry.url.clone(),
|
||||
model_id: if entry.model.trim().is_empty() { entry.name.clone() } else { entry.model.clone() },
|
||||
api_key,
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn get_paths(paths: State<'_, AppPaths>) -> Paths {
|
||||
paths.0.clone()
|
||||
@ -37,13 +77,92 @@ fn load_tasks(paths: State<'_, AppPaths>) -> tasks::LoadReport {
|
||||
tasks::load_all(&paths.0.tasks_dir)
|
||||
}
|
||||
|
||||
/// Startet einen Batch mit den angegebenen Modellen und Aufgaben-IDs.
|
||||
/// Angebundene Modelle.
|
||||
#[tauri::command]
|
||||
fn list_models(cfg: State<'_, ConfigState>) -> Result<Vec<ModelInfo>, String> {
|
||||
let c = cfg.config.lock().map_err(|e| e.to_string())?;
|
||||
Ok(c.models.iter().map(model_info).collect())
|
||||
}
|
||||
|
||||
/// Ersetzt die Modell-Liste, prüft sie und schreibt `config.toml`.
|
||||
#[tauri::command]
|
||||
fn save_models(cfg: State<'_, ConfigState>, models: Vec<ModelEntry>) -> Result<Vec<ModelInfo>, String> {
|
||||
let cleaned: Vec<ModelEntry> = models
|
||||
.into_iter()
|
||||
.map(|mut m| {
|
||||
m.name = m.name.trim().to_string();
|
||||
m.url = m.url.trim().to_string();
|
||||
m.model = m.model.trim().to_string();
|
||||
m.api_key_env = m.api_key_env.trim().to_string();
|
||||
m
|
||||
})
|
||||
.collect();
|
||||
config::validate_models(&cleaned)?;
|
||||
let mut c = cfg.config.lock().map_err(|e| e.to_string())?;
|
||||
let mut next = c.clone();
|
||||
next.models = cleaned;
|
||||
config::save(&cfg.file, &next)?;
|
||||
*c = next;
|
||||
Ok(c.models.iter().map(model_info).collect())
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct ModelTest {
|
||||
pub ok: bool,
|
||||
pub duration_ms: u128,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
/// Prüft die Verbindung zu einem Modell mit einer kurzen Anfrage.
|
||||
#[tauri::command]
|
||||
async fn test_model(cfg: State<'_, ConfigState>, name: String) -> Result<ModelTest, String> {
|
||||
let entry = {
|
||||
let c = cfg.config.lock().map_err(|e| e.to_string())?;
|
||||
c.models
|
||||
.iter()
|
||||
.find(|m| m.name == name)
|
||||
.cloned()
|
||||
.ok_or_else(|| format!("Modell {name:?} ist nicht angebunden."))?
|
||||
};
|
||||
let conn = conn_of(&entry);
|
||||
tauri::async_runtime::spawn_blocking(move || {
|
||||
let started = Instant::now();
|
||||
let result = runner::client_for(&conn).and_then(|client| {
|
||||
client
|
||||
.chat(
|
||||
&[agent::Message::new("user", "Antworte nur mit: ok")],
|
||||
&serde_json::json!([]),
|
||||
Duration::from_secs(90),
|
||||
)
|
||||
.map_err(|e| match e {
|
||||
agent::ModelError::Timeout => "Zeitlimit überschritten (90 s)".to_string(),
|
||||
agent::ModelError::Endpoint(m) => m,
|
||||
})
|
||||
});
|
||||
let duration_ms = started.elapsed().as_millis();
|
||||
match result {
|
||||
Ok(r) => ModelTest {
|
||||
ok: true,
|
||||
duration_ms,
|
||||
message: format!(
|
||||
"Antwort erhalten ({} Prompt-, {} Completion-Tokens).",
|
||||
r.prompt_tokens, r.completion_tokens
|
||||
),
|
||||
},
|
||||
Err(message) => ModelTest { ok: false, duration_ms, message },
|
||||
}
|
||||
})
|
||||
.await
|
||||
.map_err(|e| format!("Test abgebrochen: {e}"))
|
||||
}
|
||||
|
||||
/// Startet einen Batch mit den angegebenen Modellen (Anzeigenamen) und Aufgaben-IDs.
|
||||
/// Fortschritt kommt als Ereignis `batch-event`. Das Ergebnis ist die Zusammenfassung.
|
||||
#[tauri::command]
|
||||
async fn start_batch(
|
||||
app: tauri::AppHandle,
|
||||
paths: State<'_, AppPaths>,
|
||||
cfg: State<'_, Config>,
|
||||
cfg: State<'_, ConfigState>,
|
||||
run: State<'_, RunState>,
|
||||
models: Vec<String>,
|
||||
task_ids: Vec<String>,
|
||||
@ -56,10 +175,20 @@ async fn start_batch(
|
||||
if repeats == 0 {
|
||||
return Err("Wiederholungen müssen mindestens 1 sein.".into());
|
||||
}
|
||||
if run.running.swap(true, Ordering::SeqCst) {
|
||||
return Err("Ein Batch läuft bereits.".into());
|
||||
}
|
||||
run.cancel.store(false, Ordering::SeqCst);
|
||||
|
||||
let (conns, runtime, limits) = {
|
||||
let c = cfg.config.lock().map_err(|e| e.to_string())?;
|
||||
let mut conns = Vec::new();
|
||||
for name in &models {
|
||||
let entry = c
|
||||
.models
|
||||
.iter()
|
||||
.find(|m| &m.name == name)
|
||||
.ok_or_else(|| format!("Modell {name:?} ist nicht angebunden."))?;
|
||||
conns.push(conn_of(entry));
|
||||
}
|
||||
(conns, c.container_runtime.clone(), c.sandbox_limits())
|
||||
};
|
||||
|
||||
let report = tasks::load_all(&paths.0.tasks_dir);
|
||||
let selected: Vec<tasks::Task> = report
|
||||
@ -68,17 +197,20 @@ async fn start_batch(
|
||||
.filter(|t| task_ids.contains(&t.meta.id))
|
||||
.collect();
|
||||
if selected.len() != task_ids.len() {
|
||||
run.running.store(false, Ordering::SeqCst);
|
||||
return Err("Mindestens eine gewählte Aufgabe ist nicht gültig geladen.".into());
|
||||
}
|
||||
|
||||
if run.running.swap(true, Ordering::SeqCst) {
|
||||
return Err("Ein Batch läuft bereits.".into());
|
||||
}
|
||||
run.cancel.store(false, Ordering::SeqCst);
|
||||
|
||||
let jobs = runner::plan(&models, &selected, repeats);
|
||||
let run_cfg = RunConfig {
|
||||
runtime: cfg.container_runtime.clone(),
|
||||
backend: cfg.backend.clone(),
|
||||
endpoint_url: cfg.endpoint_url(),
|
||||
api_key: std::env::var(&cfg.openai_api_key_env).ok().filter(|k| !k.is_empty()),
|
||||
runtime,
|
||||
models: conns,
|
||||
data_dir: paths.0.data_dir.clone(),
|
||||
limits: cfg.sandbox_limits(),
|
||||
limits,
|
||||
};
|
||||
let db_path = paths.0.data_dir.join(DB_FILE);
|
||||
let cancel = run.cancel.clone();
|
||||
@ -114,6 +246,12 @@ fn cancel_batch(run: State<'_, RunState>) -> bool {
|
||||
running
|
||||
}
|
||||
|
||||
/// Alle bisherigen Batches, neueste zuerst.
|
||||
#[tauri::command]
|
||||
fn list_batches(paths: State<'_, AppPaths>) -> Result<Vec<BatchInfo>, String> {
|
||||
Store::open(&paths.0.data_dir.join(DB_FILE))?.list_batches()
|
||||
}
|
||||
|
||||
/// Alle gespeicherten Läufe eines Batches.
|
||||
#[tauri::command]
|
||||
fn batch_results(paths: State<'_, AppPaths>, batch_id: i64) -> Result<Vec<RunRecord>, String> {
|
||||
@ -135,7 +273,7 @@ fn run_steps(
|
||||
}
|
||||
|
||||
/// Zustand der Container-Laufzeit (Podman) für das Setup.
|
||||
#[derive(serde::Serialize)]
|
||||
#[derive(Serialize)]
|
||||
pub struct RuntimeStatus {
|
||||
pub program: String,
|
||||
pub available: bool,
|
||||
@ -143,38 +281,48 @@ pub struct RuntimeStatus {
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn runtime_status(cfg: State<'_, Config>) -> RuntimeStatus {
|
||||
let program = cfg.container_runtime.clone();
|
||||
match std::process::Command::new(&program).args(["version", "--format", "{{.Client.Version}}"]).output() {
|
||||
Ok(out) if out.status.success() => RuntimeStatus {
|
||||
program,
|
||||
available: true,
|
||||
detail: format!("Version {}", String::from_utf8_lossy(&out.stdout).trim()),
|
||||
fn runtime_status(cfg: State<'_, ConfigState>) -> Result<RuntimeStatus, String> {
|
||||
let program = cfg.config.lock().map_err(|e| e.to_string())?.container_runtime.clone();
|
||||
Ok(
|
||||
match std::process::Command::new(&program)
|
||||
.args(["version", "--format", "{{.Client.Version}}"])
|
||||
.output()
|
||||
{
|
||||
Ok(out) if out.status.success() => RuntimeStatus {
|
||||
program,
|
||||
available: true,
|
||||
detail: format!("Version {}", String::from_utf8_lossy(&out.stdout).trim()),
|
||||
},
|
||||
Ok(out) => RuntimeStatus {
|
||||
program,
|
||||
available: false,
|
||||
detail: String::from_utf8_lossy(&out.stderr).trim().to_string(),
|
||||
},
|
||||
Err(e) => RuntimeStatus {
|
||||
program,
|
||||
available: false,
|
||||
detail: format!("nicht startbar: {e}"),
|
||||
},
|
||||
},
|
||||
Ok(out) => RuntimeStatus {
|
||||
program,
|
||||
available: false,
|
||||
detail: String::from_utf8_lossy(&out.stderr).trim().to_string(),
|
||||
},
|
||||
Err(e) => RuntimeStatus {
|
||||
program,
|
||||
available: false,
|
||||
detail: format!("nicht startbar: {e}"),
|
||||
},
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/// Rangliste und Matrix eines Batches. Gewichte kommen aus den Aufgaben.
|
||||
/// Bewertung je Modell und Bereich für einen Batch. Gruppe und Gewicht kommen aus den Aufgaben.
|
||||
#[tauri::command]
|
||||
fn batch_ranking(paths: State<'_, AppPaths>, batch_id: i64) -> Result<ranking::Ranking, String> {
|
||||
let store = Store::open(&paths.0.data_dir.join(DB_FILE))?;
|
||||
let runs = store.runs_for_batch(batch_id)?;
|
||||
let weights: std::collections::BTreeMap<String, f64> = tasks::load_all(&paths.0.tasks_dir)
|
||||
let infos: BTreeMap<String, ranking::TaskInfo> = tasks::load_all(&paths.0.tasks_dir)
|
||||
.tasks
|
||||
.into_iter()
|
||||
.map(|t| (t.meta.id, t.meta.weight))
|
||||
.map(|t| {
|
||||
(
|
||||
t.meta.id.clone(),
|
||||
ranking::TaskInfo { group: t.meta.group.clone(), weight: t.meta.weight },
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
Ok(ranking::compute(batch_id, &runs, &weights))
|
||||
Ok(ranking::compute(batch_id, &runs, &infos))
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
@ -193,8 +341,9 @@ pub fn run() {
|
||||
let (paths, cfg) = config::load_or_create(&config_dir, &default_data_dir)?;
|
||||
// Datenbank einmal anlegen, damit Fehler früh sichtbar werden.
|
||||
Store::open(&paths.data_dir.join(DB_FILE))?;
|
||||
let file = paths.config_file.clone();
|
||||
app.manage(AppPaths(paths));
|
||||
app.manage(cfg);
|
||||
app.manage(ConfigState { config: Mutex::new(cfg), file });
|
||||
app.manage(RunState {
|
||||
cancel: Arc::new(AtomicBool::new(false)),
|
||||
running: Arc::new(AtomicBool::new(false)),
|
||||
@ -204,8 +353,12 @@ pub fn run() {
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
get_paths,
|
||||
load_tasks,
|
||||
list_models,
|
||||
save_models,
|
||||
test_model,
|
||||
start_batch,
|
||||
cancel_batch,
|
||||
list_batches,
|
||||
batch_results,
|
||||
batch_ranking,
|
||||
run_steps,
|
||||
|
||||
Reference in New Issue
Block a user