MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / upload_batch

Method upload_batch

tools/xtask-llm-benchmark/src/api/client.rs:47–127  ·  view source on GitHub ↗

Upload a batch of run outcomes for a single (lang, mode) combination. Normalizes model names and sanitizes volatile fields before upload. If `analysis` is provided, it is stored in the `llm_benchmark_analysis` table.

(&self, mode: &str, outcomes: &[RunOutcome], analysis: Option<&str>)

Source from the content-addressed store, hash-verified

45 /// Normalizes model names and sanitizes volatile fields before upload.
46 /// If `analysis` is provided, it is stored in the `llm_benchmark_analysis` table.
47 pub fn upload_batch(&self, mode: &str, outcomes: &[RunOutcome], analysis: Option<&str>) -> Result<usize> {
48 if outcomes.is_empty() {
49 return Ok(0);
50 }
51
52 let mode = canonical_mode(mode);
53
54 // Build in-memory Results so we can normalize model names
55 let mut results = Results::default();
56 {
57 use crate::bench::normalize::{canonical_model_name, ensure_lang, ensure_mode, ensure_model};
58
59 for r in outcomes {
60 let lang_v = ensure_lang(&mut results, &r.lang);
61 let mode_v = ensure_mode(lang_v, mode, Some(r.hash.clone()));
62 let canonical_name = canonical_model_name(&r.model_name);
63 let model_v = ensure_model(mode_v, &canonical_name);
64 model_v.route_api_model = r.route_api_model.clone();
65
66 let mut sanitized = r.clone();
67 sanitized.sanitize_for_commit();
68 model_v.tasks.insert(r.task.clone(), sanitized);
69 }
70 }
71 normalize_model_names(&mut results);
72
73 let url = format!("{}/api/llm-benchmark-upload", self.base_url);
74 let mut total_uploaded = 0usize;
75
76 for lang_entry in &results.languages {
77 for mode_entry in &lang_entry.modes {
78 // Serialize models and inject analysis into each model object if provided
79 let mut models_json = serde_json::to_value(&mode_entry.models)?;
80 if let Some(text) = analysis
81 && let Some(arr) = models_json.as_array_mut()
82 {
83 for model in arr {
84 model["analysis"] = json!(text);
85 }
86 }
87
88 let payload = json!({
89 "lang": lang_entry.lang,
90 "mode": mode_entry.mode,
91 "hash": mode_entry.hash,
92 "models": models_json,
93 });
94
95 let resp = self
96 .client
97 .post(&url)
98 .header("Authorization", format!("Bearer {}", self.api_key))
99 .header("Content-Type", "application/json")
100 .json(&payload)
101 .send()
102 .with_context(|| format!("upload failed for {}/{}", lang_entry.lang, mode_entry.mode))?;
103
104 if resp.status().is_success() {

Calls 15

canonical_modeFunction · 0.85
ensure_langFunction · 0.85
ensure_modeFunction · 0.85
canonical_model_nameFunction · 0.85
ensure_modelFunction · 0.85
normalize_model_namesFunction · 0.85
sanitize_for_commitMethod · 0.80
is_successMethod · 0.80
statusMethod · 0.80
unwrap_orMethod · 0.80
insertMethod · 0.65
sendMethod · 0.65

Tested by

no test coverage detected