feat: tools bei Modellen ohne Werkzeug-Vorlage klar ablehnen, nicht bestandenen Werkzeug-Test anzeigen (#1268)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 12:28:21 +01:00
parent 21d419aab1
commit 2ad3121c7c
9 changed files with 168 additions and 3 deletions

View File

@ -85,6 +85,12 @@ pub trait Engine: Send + Sync {
/// Adresse, unter der die Instanz erreichbar ist.
fn endpoint(&self, instance: &InstanceHandle) -> Endpoint;
/// Kann das geladene Modell Werkzeuge (`tools`) entgegennehmen? `None`: Die Engine sagt dazu nichts,
/// die Anfrage geht unverändert weiter.
async fn tool_support(&self, _instance: &InstanceHandle) -> Option<bool> {
None
}
/// Misst den echten Ressourcenverbrauch.
async fn measure(&self, instance: &InstanceHandle) -> Usage;
}

View File

@ -77,6 +77,8 @@ pub(crate) struct CommandLine {
struct Managed {
child: Child,
port: u16,
/// Laut `/props` kennt die Chat-Vorlage Werkzeuge (`None`: keine Auskunft).
tools: Option<bool>,
}
pub struct LlamaCppEngine {
@ -265,10 +267,17 @@ impl LlamaCppEngine {
}
let pid = child.id();
let tools = template_tool_support(port).await;
if tools == Some(false) {
tracing::info!(
instance_id = id,
"Die Chat-Vorlage des Modells kennt keine Werkzeuge"
);
}
self.children
.lock()
.await
.insert(id, Managed { child, port });
.insert(id, Managed { child, port, tools });
Ok(InstanceHandle { id, pid, port })
}
@ -464,6 +473,14 @@ impl Engine for LlamaCppEngine {
}
}
async fn tool_support(&self, instance: &InstanceHandle) -> Option<bool> {
self.children
.lock()
.await
.get(&instance.id)
.and_then(|m| m.tools)
}
async fn measure(&self, instance: &InstanceHandle) -> Usage {
let Some(pid) = instance.pid else {
return Usage::default();
@ -477,6 +494,24 @@ impl Engine for LlamaCppEngine {
}
}
/// Fragt `GET /props`, ob die Chat-Vorlage Werkzeuge kennt (`chat_template_caps.supports_tools`). Kennt sie
/// keine, lässt llama-server die Definitionen ohne Meldung weg (→ #1268). Ältere Versionen und Fehler: `None`.
async fn template_tool_support(port: u16) -> Option<bool> {
let response = reqwest::Client::new()
.get(format!("http://127.0.0.1:{port}/props"))
.timeout(Duration::from_secs(5))
.send()
.await
.ok()?;
if !response.status().is_success() {
return None;
}
let props: serde_json::Value = serde_json::from_slice(&response.bytes().await.ok()?).ok()?;
props
.pointer("/chat_template_caps/supports_tools")?
.as_bool()
}
/// Liest aus der Ausgabe von `nvidia-smi --query-compute-apps=pid,used_memory
/// --format=csv,noheader,nounits` den VRAM (MiB) eines Prozesses; mehrere
/// Zeilen (mehrere GPUs) werden addiert.