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:
@ -13,6 +13,59 @@ pub const CONFIG_FILE_NAME: &str = "config.toml";
|
||||
/// Aufgaben, die ein Paket installiert. Gilt, wenn weder die Konfiguration noch der Datenordner Aufgaben angeben.
|
||||
pub const SYSTEM_TASKS_DIR: &str = "/usr/share/coding-bench/tasks";
|
||||
|
||||
/// Ein angebundenes Modell: Anzeigename, Adapter und Endpunkt.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(default, deny_unknown_fields)]
|
||||
pub struct ModelEntry {
|
||||
/// Anzeigename, eindeutig. Erscheint in Ranglisten.
|
||||
pub name: String,
|
||||
/// `ollama` oder `openai` (OpenAI-kompatibel, z. B. strata).
|
||||
pub adapter: String,
|
||||
/// Basis-URL des Servers, z. B. `http://host:11434` oder `http://host:8082/v1`.
|
||||
pub url: String,
|
||||
/// Modell-ID, die an den Server gesendet wird. Leer = Anzeigename.
|
||||
pub model: String,
|
||||
/// Name der Umgebungsvariable mit dem API-Schlüssel. Leer = kein Schlüssel.
|
||||
pub api_key_env: String,
|
||||
}
|
||||
|
||||
impl Default for ModelEntry {
|
||||
fn default() -> Self {
|
||||
ModelEntry {
|
||||
name: String::new(),
|
||||
adapter: "ollama".into(),
|
||||
url: String::new(),
|
||||
model: String::new(),
|
||||
api_key_env: String::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub const ADAPTERS: [&str; 2] = ["ollama", "openai"];
|
||||
|
||||
/// Prüft eine Modell-Liste: Namen nicht leer und eindeutig, Adapter bekannt, URL gesetzt.
|
||||
pub fn validate_models(models: &[ModelEntry]) -> Result<(), String> {
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
for m in models {
|
||||
if m.name.trim().is_empty() {
|
||||
return Err("Ein Modell hat keinen Namen.".into());
|
||||
}
|
||||
if !seen.insert(m.name.trim().to_string()) {
|
||||
return Err(format!("Der Name {:?} kommt doppelt vor.", m.name));
|
||||
}
|
||||
if !ADAPTERS.contains(&m.adapter.as_str()) {
|
||||
return Err(format!(
|
||||
"{}: Adapter {:?} unbekannt (erlaubt: ollama, openai).",
|
||||
m.name, m.adapter
|
||||
));
|
||||
}
|
||||
if m.url.trim().is_empty() {
|
||||
return Err(format!("{}: URL fehlt.", m.name));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Rohe Konfiguration, so wie sie in der Datei steht.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(default, deny_unknown_fields)]
|
||||
@ -23,13 +76,15 @@ pub struct Config {
|
||||
pub tasks_dir: Option<PathBuf>,
|
||||
/// Container-Programm für die Sandbox (Podman-CLI).
|
||||
pub container_runtime: String,
|
||||
/// Modell-Backend: `ollama` oder `openai` (OpenAI-kompatibel, z. B. strata).
|
||||
/// Angebundene Modelle. Wird in der Oberfläche gepflegt.
|
||||
pub models: Vec<ModelEntry>,
|
||||
/// Veraltet, wird ignoriert. Bleibt nur, damit alte Dateien weiter laden.
|
||||
pub backend: String,
|
||||
/// Ollama-Endpunkt für alle Modelle (Phase 1).
|
||||
/// Veraltet, wird ignoriert.
|
||||
pub ollama_url: String,
|
||||
/// OpenAI-kompatibler Endpunkt, vollständige URL inkl. `/v1/chat/completions`.
|
||||
/// Veraltet, wird ignoriert.
|
||||
pub openai_url: String,
|
||||
/// Name der Umgebungsvariable mit dem API-Schlüssel. Der Schlüssel selbst steht nicht in der Datei.
|
||||
/// Veraltet, wird ignoriert.
|
||||
pub openai_api_key_env: String,
|
||||
/// Speicherlimit pro Lauf, Podman-Schreibweise.
|
||||
pub sandbox_memory: String,
|
||||
@ -44,10 +99,11 @@ impl Default for Config {
|
||||
data_dir: None,
|
||||
tasks_dir: None,
|
||||
container_runtime: "podman".into(),
|
||||
backend: "ollama".into(),
|
||||
ollama_url: "http://127.0.0.1:11434".into(),
|
||||
openai_url: "http://192.168.12.4:8082/v1/chat/completions".into(),
|
||||
openai_api_key_env: "STRATA_API_KEY".into(),
|
||||
models: Vec::new(),
|
||||
backend: String::new(),
|
||||
ollama_url: String::new(),
|
||||
openai_url: String::new(),
|
||||
openai_api_key_env: String::new(),
|
||||
sandbox_memory: limits.memory,
|
||||
sandbox_cpus: limits.cpus,
|
||||
}
|
||||
@ -68,15 +124,6 @@ impl Config {
|
||||
toml::from_str(text).map_err(|e| format!("config.toml ist ungültig: {e}"))
|
||||
}
|
||||
|
||||
/// Endpunkt des gewählten Backends.
|
||||
pub fn endpoint_url(&self) -> String {
|
||||
if self.backend == "openai" {
|
||||
self.openai_url.clone()
|
||||
} else {
|
||||
self.ollama_url.clone()
|
||||
}
|
||||
}
|
||||
|
||||
/// Ressourcenlimits der Sandbox aus der Konfiguration.
|
||||
pub fn sandbox_limits(&self) -> Limits {
|
||||
Limits {
|
||||
@ -103,6 +150,14 @@ impl Config {
|
||||
}
|
||||
}
|
||||
|
||||
/// Schreibt die Konfiguration zurück. Kommentare der alten Datei gehen dabei verloren.
|
||||
pub fn save(config_file: &Path, config: &Config) -> Result<(), String> {
|
||||
let text = toml::to_string_pretty(config)
|
||||
.map_err(|e| format!("Konfiguration nicht serialisierbar: {e}"))?;
|
||||
fs::write(config_file, format!("# coding-bench Konfiguration\n{text}"))
|
||||
.map_err(|e| format!("{} nicht schreibbar: {e}", config_file.display()))
|
||||
}
|
||||
|
||||
/// Lädt die Konfiguration aus `config_dir/config.toml`, legt die Datei bei Bedarf
|
||||
/// mit Standardwerten an und stellt sicher, dass der Datenordner existiert.
|
||||
pub fn load_or_create(config_dir: &Path, default_data_dir: &Path) -> Result<(Paths, Config), String> {
|
||||
@ -157,10 +212,34 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ollama_url_hat_standard_und_ist_ueberschreibbar() {
|
||||
assert_eq!(Config::default().ollama_url, "http://127.0.0.1:11434");
|
||||
let c = Config::parse("ollama_url = \"http://srv04:11434\"\n").unwrap();
|
||||
assert_eq!(c.ollama_url, "http://srv04:11434");
|
||||
fn modelle_werden_gelesen_und_geprueft() {
|
||||
let c = Config::parse(
|
||||
"[[models]]\nname = \"lokal\"\nadapter = \"ollama\"\nurl = \"http://h:11434\"\nmodel = \"qwen3:0.6b\"\n\n[[models]]\nname = \"strata\"\nadapter = \"openai\"\nurl = \"http://h:8082/v1\"\n",
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(c.models.len(), 2);
|
||||
assert_eq!(c.models[1].adapter, "openai");
|
||||
assert!(validate_models(&c.models).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn modell_pruefung_findet_fehler() {
|
||||
let m = |name: &str, adapter: &str, url: &str| ModelEntry {
|
||||
name: name.into(),
|
||||
adapter: adapter.into(),
|
||||
url: url.into(),
|
||||
..ModelEntry::default()
|
||||
};
|
||||
assert!(validate_models(&[m("", "ollama", "http://x")]).is_err());
|
||||
assert!(validate_models(&[m("a", "ollama", "http://x"), m("a", "ollama", "http://y")]).is_err());
|
||||
assert!(validate_models(&[m("a", "gpt", "http://x")]).is_err());
|
||||
assert!(validate_models(&[m("a", "ollama", " ")]).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alte_config_mit_veralteten_feldern_laedt_weiter() {
|
||||
let c = Config::parse("ollama_url = \"http://srv04:11434\"\nbackend = \"openai\"\n").unwrap();
|
||||
assert!(c.models.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user