feat(ui): Fähigkeiten je Modell als Symbole mit Herkunft auf der Modelle-Seite (#1081)
- Neue Spalte „Kann“: Chat, Bilder, Werkzeuge, Embeddings, Streaming, Completions. - Herkunft sichtbar: grau = Fähigkeit der Engine, für das Modell nicht geprüft; farbig = aus den Dateien erkannt (llama.cpp mit mmproj im Ordner oder darüber, Strata mit vision in der Laufkonfiguration). - Modul ui/faehigkeiten.rs mit Einheitentests; im Browser mit den echten Adaptern geprüft. - Offen: Test am Modell (Stufe 3), GGUF-Kopfdaten, Ollama je Modell. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -46,6 +46,7 @@ mod auswertung;
|
||||
mod benutzer;
|
||||
mod chat;
|
||||
mod engines;
|
||||
mod faehigkeiten;
|
||||
mod logs;
|
||||
mod startprofiles;
|
||||
mod verwaltung;
|
||||
@ -1191,6 +1192,8 @@ dl.daten dd{margin:0;overflow-wrap:anywhere}dl.daten .breit-zeile{grid-column:1/
|
||||
pre.befehl{margin:0;padding:.6rem .8rem;background:var(--bg);border:1px solid var(--border);border-radius:10px;font-family:ui-monospace,"JetBrains Mono",Menlo,monospace;font-size:.82rem;white-space:pre-wrap;overflow-wrap:anywhere}
|
||||
.engine h2{margin:0}.chips{display:flex;flex-wrap:wrap;gap:.35rem;margin:.7rem 0 .2rem}
|
||||
.engine .zeile{gap:.5rem .7rem}
|
||||
td.faehig{white-space:nowrap}.fsym{width:1.15rem;height:1.15rem;margin-right:.3rem;vertical-align:middle;fill:none;stroke:currentColor;stroke-width:1.6;stroke-linecap:round;stroke-linejoin:round}
|
||||
.fsym.datei{color:var(--accent-strong)}.fsym.engine{color:var(--muted);opacity:.65}
|
||||
footer label{display:inline-flex;gap:.35rem;align-items:center}footer select{padding:.15rem .4rem;font-size:.8rem}
|
||||
.tabellenleiste{display:flex;flex-wrap:wrap;gap:.5rem .7rem;align-items:center;margin:0 0 .7rem}.tabellenleiste input[type=search]{min-width:12rem}
|
||||
th.sortierbar{cursor:pointer;user-select:none}th.sortierbar:hover{color:var(--text)}
|
||||
|
||||
255
crates/nexus-api/src/ui/faehigkeiten.rs
Normal file
255
crates/nexus-api/src/ui/faehigkeiten.rs
Normal file
@ -0,0 +1,255 @@
|
||||
//! Fähigkeiten je Modell als Symbole auf der Modelle-Seite (#1081).
|
||||
//!
|
||||
//! Gezeigt wird nur, woher das Wissen stammt: **Engine** (die Engine kann es grundsätzlich, ob das
|
||||
//! Modell es kann, ist nicht geprüft) und **Datei** (aus den Dateien des Modells erkannt, zum Beispiel
|
||||
//! ein `mmproj` neben der Modelldatei). Ein Test am Modell selbst gibt es noch nicht; bis dahin
|
||||
//! steht in keinem Symbol „geprüft“.
|
||||
|
||||
use super::esc;
|
||||
use nexus_adapter::Capabilities;
|
||||
use std::{fs, path::Path};
|
||||
|
||||
/// Woher eine Angabe stammt.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
pub(super) enum Herkunft {
|
||||
Engine,
|
||||
Datei,
|
||||
}
|
||||
|
||||
/// Symbole in fester Reihenfolge: Chat, Bilder (Vision), Werkzeuge, Embeddings, Streaming, Completions.
|
||||
pub(super) fn capability_icons(caps: &Capabilities) -> Vec<&'static str> {
|
||||
let mut icons = Vec::new();
|
||||
if caps.chat {
|
||||
icons.push("chat");
|
||||
}
|
||||
if caps.images {
|
||||
icons.push("vision");
|
||||
}
|
||||
if caps.tool_calling {
|
||||
icons.push("tools");
|
||||
}
|
||||
if caps.embeddings {
|
||||
icons.push("embed");
|
||||
}
|
||||
if caps.streaming {
|
||||
icons.push("stream");
|
||||
}
|
||||
if caps.completions {
|
||||
icons.push("completion");
|
||||
}
|
||||
icons
|
||||
}
|
||||
|
||||
const MAX_ENTRIES: usize = 512;
|
||||
const MAX_JSON_BYTES: u64 = 64 * 1024;
|
||||
|
||||
/// Hat das Verzeichnis eine `mmproj*.gguf`? (Begrenzte Liste, keine Unterordner, keine Symlinks.)
|
||||
fn hat_mmproj(dir: &Path) -> bool {
|
||||
let Ok(entries) = fs::read_dir(dir) else {
|
||||
return false;
|
||||
};
|
||||
entries.take(MAX_ENTRIES).flatten().any(|e| {
|
||||
let name = e.file_name();
|
||||
let name = name.to_string_lossy().to_ascii_lowercase();
|
||||
name.starts_with("mmproj")
|
||||
&& name.ends_with(".gguf")
|
||||
&& e.file_type().is_ok_and(|t| t.is_file())
|
||||
})
|
||||
}
|
||||
|
||||
/// Was die Dateien eines Modells verraten. Nur Dinge, die sich sicher aus dem Dateisystem ergeben:
|
||||
/// llama.cpp: `mmproj` im Ordner der Modelldatei oder im Ordner darüber (dort liegt sie bei geteilten
|
||||
/// Modellordnern); Strata: der Eintrag `vision` in der Laufkonfiguration.
|
||||
pub(super) fn aus_dateien(engine: &str, path: &str) -> Vec<&'static str> {
|
||||
let mut found = Vec::new();
|
||||
let p = Path::new(path);
|
||||
match engine {
|
||||
"llama.cpp" => {
|
||||
let dir = p.parent();
|
||||
if dir.is_some_and(hat_mmproj) || dir.and_then(Path::parent).is_some_and(hat_mmproj) {
|
||||
found.push("vision");
|
||||
}
|
||||
}
|
||||
"strata" => {
|
||||
let meta = fs::symlink_metadata(p);
|
||||
if meta.is_ok_and(|m| m.is_file() && m.len() <= MAX_JSON_BYTES)
|
||||
&& let Ok(text) = fs::read_to_string(p)
|
||||
&& let Ok(json) = serde_json::from_str::<serde_json::Value>(&text)
|
||||
&& json
|
||||
.get("vision")
|
||||
.is_some_and(|v| !v.is_null() && *v != serde_json::Value::Bool(false))
|
||||
{
|
||||
found.push("vision");
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
found
|
||||
}
|
||||
|
||||
/// Alle Symbole eines Modells mit Herkunft: erst aus den Dateien, dann die der Engine (ohne Doppelte).
|
||||
pub(super) fn symbole(
|
||||
caps: Option<&Capabilities>,
|
||||
engine: &str,
|
||||
path: &str,
|
||||
) -> Vec<(&'static str, Herkunft)> {
|
||||
let mut out: Vec<(&'static str, Herkunft)> = Vec::new();
|
||||
let datei = aus_dateien(engine, path);
|
||||
let engine_icons = caps.map(capability_icons).unwrap_or_default();
|
||||
for key in ["chat", "vision", "tools", "embed", "stream", "completion"] {
|
||||
if datei.contains(&key) {
|
||||
out.push((key, Herkunft::Datei));
|
||||
} else if engine_icons.contains(&key) {
|
||||
out.push((key, Herkunft::Engine));
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
fn svg(key: &str) -> &'static str {
|
||||
match key {
|
||||
"chat" => "<path d=\"M4 5h16v11H9l-5 4z\"/>",
|
||||
"vision" => {
|
||||
"<path d=\"M2 12s4-7 10-7 10 7 10 7-4 7-10 7S2 12 2 12z\"/><circle cx=\"12\" cy=\"12\" r=\"3\"/>"
|
||||
}
|
||||
"tools" => "<path d=\"M14 6a4 4 0 0 0-5 5L3 17l4 4 6-6a4 4 0 0 0 5-5l-3 3-3-1-1-3z\"/>",
|
||||
"embed" => {
|
||||
"<circle cx=\"6\" cy=\"6\" r=\"2\"/><circle cx=\"18\" cy=\"8\" r=\"2\"/><circle cx=\"9\" cy=\"18\" r=\"2\"/><path d=\"M7.5 7.5l9 1M7 8l2 8M17 10l-7 7\"/>"
|
||||
}
|
||||
"stream" => "<path d=\"M4 8h12M4 12h16M4 16h9\"/>",
|
||||
_ => "<path d=\"M8 6l-5 6 5 6M16 6l5 6-5 6\"/>",
|
||||
}
|
||||
}
|
||||
|
||||
fn titel(key: &str) -> &'static str {
|
||||
match key {
|
||||
"chat" => "Chat",
|
||||
"vision" => "Bilder verstehen (Vision)",
|
||||
"tools" => "Werkzeuge aufrufen (Tool Calling)",
|
||||
"embed" => "Embeddings",
|
||||
"stream" => "Streaming",
|
||||
_ => "Completions",
|
||||
}
|
||||
}
|
||||
|
||||
/// Die Zelle für die Tabelle: je Symbol ein Bild mit Hinweistext zur Herkunft.
|
||||
pub(super) fn zelle(symbole: &[(&'static str, Herkunft)]) -> String {
|
||||
if symbole.is_empty() {
|
||||
return "<td class=\"faehig\"><span class=\"muted\">–</span></td>".to_string();
|
||||
}
|
||||
let icons: String = symbole
|
||||
.iter()
|
||||
.map(|(key, herkunft)| {
|
||||
let (klasse, hinweis) = match herkunft {
|
||||
Herkunft::Datei => ("datei", "aus den Dateien des Modells erkannt"),
|
||||
Herkunft::Engine => (
|
||||
"engine",
|
||||
"Fähigkeit der Engine, für dieses Modell nicht geprüft",
|
||||
),
|
||||
};
|
||||
format!(
|
||||
"<svg class=\"fsym {klasse}\" viewBox=\"0 0 24 24\" role=\"img\" aria-label=\"{t}: {h}\"><title>{t}: {h}</title>{p}</svg>",
|
||||
t = esc(titel(key)),
|
||||
h = esc(hinweis),
|
||||
p = svg(key),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
format!("<td class=\"faehig\">{icons}</td>")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn caps(
|
||||
chat: bool,
|
||||
images: bool,
|
||||
tools: bool,
|
||||
embed: bool,
|
||||
stream: bool,
|
||||
compl: bool,
|
||||
) -> Capabilities {
|
||||
Capabilities {
|
||||
chat,
|
||||
completions: compl,
|
||||
embeddings: embed,
|
||||
streaming: stream,
|
||||
tool_calling: tools,
|
||||
images,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn icons_in_fester_reihenfolge() {
|
||||
assert!(capability_icons(&caps(false, false, false, false, false, false)).is_empty());
|
||||
assert_eq!(
|
||||
capability_icons(&caps(true, false, false, false, false, false)),
|
||||
["chat"]
|
||||
);
|
||||
assert_eq!(
|
||||
capability_icons(&caps(true, true, false, false, false, false)),
|
||||
["chat", "vision"]
|
||||
);
|
||||
assert_eq!(
|
||||
capability_icons(&caps(true, true, true, true, true, true)),
|
||||
["chat", "vision", "tools", "embed", "stream", "completion"]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mmproj_neben_oder_ueber_der_modelldatei_zeigt_vision() {
|
||||
let base = std::env::temp_dir().join(format!("nexus-faehig-{}", std::process::id()));
|
||||
let _ = fs::remove_dir_all(&base);
|
||||
let sub = base.join("modell");
|
||||
fs::create_dir_all(&sub).unwrap();
|
||||
let datei = sub.join("m.gguf");
|
||||
fs::write(&datei, b"x").unwrap();
|
||||
assert!(aus_dateien("llama.cpp", datei.to_str().unwrap()).is_empty());
|
||||
fs::write(base.join("mmproj-F16.gguf"), b"x").unwrap();
|
||||
assert_eq!(
|
||||
aus_dateien("llama.cpp", datei.to_str().unwrap()),
|
||||
["vision"]
|
||||
);
|
||||
fs::write(sub.join("mmproj-x.gguf"), b"x").unwrap();
|
||||
assert_eq!(
|
||||
aus_dateien("llama.cpp", datei.to_str().unwrap()),
|
||||
["vision"]
|
||||
);
|
||||
// Andere Engines lesen kein mmproj.
|
||||
assert!(aus_dateien("ollama", datei.to_str().unwrap()).is_empty());
|
||||
let _ = fs::remove_dir_all(&base);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strata_vision_steht_in_der_laufkonfiguration() {
|
||||
let base = std::env::temp_dir().join(format!("nexus-faehig-s-{}", std::process::id()));
|
||||
fs::create_dir_all(&base).unwrap();
|
||||
let mit = base.join("mit.json");
|
||||
let ohne = base.join("ohne.json");
|
||||
let aus = base.join("aus.json");
|
||||
fs::write(&mit, br#"{"vision": {"mmproj": "x"}}"#).unwrap();
|
||||
fs::write(&ohne, br#"{"gpu": [0]}"#).unwrap();
|
||||
fs::write(&aus, br#"{"vision": false}"#).unwrap();
|
||||
assert_eq!(aus_dateien("strata", mit.to_str().unwrap()), ["vision"]);
|
||||
assert!(aus_dateien("strata", ohne.to_str().unwrap()).is_empty());
|
||||
assert!(aus_dateien("strata", aus.to_str().unwrap()).is_empty());
|
||||
assert!(aus_dateien("strata", "/gibt/es/nicht.json").is_empty());
|
||||
let _ = fs::remove_dir_all(&base);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn herkunft_datei_geht_vor_engine_ohne_doppelte() {
|
||||
let c = caps(true, false, false, false, true, false);
|
||||
let s = symbole(Some(&c), "ollama", "qwen3:0.6b");
|
||||
assert_eq!(
|
||||
s,
|
||||
vec![("chat", Herkunft::Engine), ("stream", Herkunft::Engine)]
|
||||
);
|
||||
let leer = symbole(None, "unbekannt", "");
|
||||
assert!(leer.is_empty());
|
||||
assert!(zelle(&leer).contains("–"));
|
||||
let html = zelle(&s);
|
||||
assert!(html.contains("class=\"fsym engine\"") && html.contains("nicht geprüft"));
|
||||
}
|
||||
}
|
||||
@ -136,6 +136,13 @@ fn models_table(state: &AppState, viewer: &Viewer) -> String {
|
||||
.to_string();
|
||||
}
|
||||
let view = state.runtime.scheduler_view();
|
||||
// Fähigkeiten der Engines (Name -> Fähigkeiten), für die Symbole je Modell (#1081).
|
||||
let engine_caps: std::collections::HashMap<String, nexus_adapter::Capabilities> = state
|
||||
.runtime
|
||||
.engine_overview()
|
||||
.into_iter()
|
||||
.map(|(name, info, _)| (name, info.capabilities))
|
||||
.collect();
|
||||
let body: String = rows
|
||||
.iter()
|
||||
.map(|m| {
|
||||
@ -186,6 +193,14 @@ fn models_table(state: &AppState, viewer: &Viewer) -> String {
|
||||
Some(c) => format!("{c}"),
|
||||
None => "<span class=\"muted\" title=\"Standard der Engine\">Standard</span>".to_string(),
|
||||
};
|
||||
let faehig = {
|
||||
let engine = m.engine.as_deref().unwrap_or("");
|
||||
super::faehigkeiten::zelle(&super::faehigkeiten::symbole(
|
||||
engine_caps.get(engine),
|
||||
engine,
|
||||
&m.path,
|
||||
))
|
||||
};
|
||||
let context_attr = m.context.map(|c| format!(" data-wert=\"{c}\"")).unwrap_or_default();
|
||||
let memory_attr = m
|
||||
.measured_mb
|
||||
@ -202,7 +217,7 @@ fn models_table(state: &AppState, viewer: &Viewer) -> String {
|
||||
};
|
||||
let row_id = format!("modell-{}", dialog_id(&m.name));
|
||||
format!(
|
||||
"<tr id=\"{row_id}\"><td class=\"name\">{}</td><td>{}</td><td>{}</td><td>{}</td><td class=\"num\"{context_attr}>{context}</td>\
|
||||
"<tr id=\"{row_id}\"><td class=\"name\">{}</td><td>{}</td><td>{}</td>{faehig}<td>{}</td><td class=\"num\"{context_attr}>{context}</td>\
|
||||
<td class=\"num\"{memory_attr}>{memory}</td><td>{state_chip}</td>{actions}</tr>",
|
||||
esc(&m.name),
|
||||
m.engine
|
||||
@ -223,8 +238,9 @@ fn models_table(state: &AppState, viewer: &Viewer) -> String {
|
||||
})
|
||||
.collect();
|
||||
format!(
|
||||
"<div class=\"breit\"><table data-filtern=\"modelle\"><thead><tr><th data-spalte=\"name\">Name</th><th data-spalte=\"engine\" data-filter>Engine</th><th data-spalte=\"status\" data-filter>Status</th><th>GPUs</th>\
|
||||
<th class=\"num\" data-spalte=\"kontext\" data-zahl>Kontext</th><th class=\"num\" data-spalte=\"speicher\" data-zahl>Speicher</th><th data-spalte=\"zustand\" data-filter>Zustand</th>{}</tr></thead><tbody>{body}</tbody></table></div>",
|
||||
"<div class=\"breit\"><table data-filtern=\"modelle\"><thead><tr><th data-spalte=\"name\">Name</th><th data-spalte=\"engine\" data-filter>Engine</th><th data-spalte=\"status\" data-filter>Status</th><th>Kann</th><th>GPUs</th>\
|
||||
<th class=\"num\" data-spalte=\"kontext\" data-zahl>Kontext</th><th class=\"num\" data-spalte=\"speicher\" data-zahl>Speicher</th><th data-spalte=\"zustand\" data-filter>Zustand</th>{}</tr></thead><tbody>{body}</tbody></table></div>\
|
||||
<p class=\"klein\">Kann: farbige Symbole sind aus den Dateien des Modells erkannt (zum Beispiel eine Bild-Zusatzdatei), graue sind Fähigkeiten der Engine, für das einzelne Modell nicht geprüft.</p>",
|
||||
if viewer.admin() { "<th></th>" } else { "" }
|
||||
)
|
||||
}
|
||||
|
||||
@ -1163,6 +1163,19 @@ async fn pwa_manifest_und_symbole_sind_ohne_sitzung_lesbar() {
|
||||
assert!(!login.contains("serviceWorker"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn modelle_zeigen_faehigkeiten_mit_herkunft() {
|
||||
let gw = gateway(0, false).await;
|
||||
let cookie = ui_cookie(&gw).await;
|
||||
let (_, _, teil) = ui_get(&gw, "/ui/teil/modelle", Some(&cookie)).await;
|
||||
// Spalte „Kann“ mit Symbolen; ohne Test am Modell steht nirgends „geprüft“ als Herkunft.
|
||||
assert!(teil.contains("<th>Kann</th>") && teil.contains("class=\"faehig\""));
|
||||
// Die Attrappen des Harness melden keine Fähigkeiten; die Symbole und ihre Herkunft prüfen die
|
||||
// Einheitentests in `ui/faehigkeiten.rs`, die echten Engines der Browser-Test auf dem Dienst.
|
||||
assert!(!teil.contains("gemessen und geprüft"));
|
||||
assert!(teil.contains("Kann: farbige Symbole"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn styleguide_tokens_theme_und_playground_layout_sind_eingebunden() {
|
||||
let gw = gateway(0, false).await;
|
||||
|
||||
Reference in New Issue
Block a user