learn: score_ranges is now required; short-circuit on empty

vllm's /v1/score endpoint made score_ranges a required field (the
messages-mode fallback that used to pattern-scan for assistant
boundaries is gone). Always send the field, and if we have nothing to
score, skip the HTTP round-trip entirely instead of letting the server
422 us.

Response parsing is unchanged — serde ignores the renamed range_index
field and the dropped role field since we only extract total_logprob.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-16 12:19:28 -04:00
parent e5dd8312c7
commit 77822992c8

View file

@ -129,16 +129,18 @@ async fn call_score(
ranges: &[(usize, usize)], ranges: &[(usize, usize)],
priority: Option<i32>, priority: Option<i32>,
) -> anyhow::Result<Vec<ScoreResult>> { ) -> anyhow::Result<Vec<ScoreResult>> {
// Nothing to score — skip the round-trip.
if ranges.is_empty() {
return Ok(Vec::new());
}
let url = format!("{}/score", client.base_url()); let url = format!("{}/score", client.base_url());
let auth = format!("Bearer {}", client.api_key()); let auth = format!("Bearer {}", client.api_key());
let mut body = serde_json::json!({ let mut body = serde_json::json!({
"model": client.model, "model": client.model,
"prompt": prompt, "prompt": prompt,
"score_ranges": ranges,
"logprobs": 1, "logprobs": 1,
}); });
if !ranges.is_empty() {
body["score_ranges"] = serde_json::json!(ranges);
}
if let Some(p) = priority { if let Some(p) = priority {
body["priority"] = serde_json::json!(p); body["priority"] = serde_json::json!(p);
} }