Skip to main content

gglib_core/domain/benchmark/
compare.rs

1//! Compare-mode benchmark types: configuration and per-model results.
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5
6use crate::domain::inference::InferenceConfig;
7
8/// Configuration for a compare benchmark run.
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct CompareConfig {
11    /// Models to benchmark (by database ID), run sequentially.
12    pub model_ids: Vec<i64>,
13    /// Prompt text to send to every model.
14    pub prompt: String,
15    /// Optional system prompt.
16    pub system_prompt: Option<String>,
17    /// Per-request inference overrides (`temperature`, `max_tokens`, etc.).
18    pub inference: Option<InferenceConfig>,
19    /// Override the llama-server context window size for this run.
20    ///
21    /// When `None` the benchmark service falls back to the app-wide
22    /// `default_context_size` setting (same fallback the proxy uses).
23    #[serde(default)]
24    pub ctx_size: Option<u64>,
25}
26
27/// Result of running a single model through a compare (inference) benchmark.
28///
29/// All timing fields are `Option<f64>` — llama-server may omit the `timings`
30/// object. Missing values are stored as `NULL` in the database and surfaced as
31/// `None` in the API; they never cause a panic.
32#[derive(Debug, Clone, Serialize, Deserialize)]
33pub struct ModelCompareResult {
34    /// Database ID of this result row (set after persistence).
35    pub id: Option<i64>,
36    /// Foreign key → `models.id`.
37    pub model_id: i64,
38    /// Foreign key → `benchmark_runs.id` (nullable; SET NULL on run delete).
39    pub run_id: Option<i64>,
40    /// Prompt text sent to this model.
41    pub prompt_text: String,
42    /// Optional system prompt.
43    pub system_prompt: Option<String>,
44    /// Full response text accumulated from the stream.
45    pub response_text: String,
46    /// `true` if the response was cut short (`finish_reason == "length"`).
47    pub was_truncated: bool,
48    /// Number of prompt tokens reported by the model.
49    pub prompt_tokens: Option<i64>,
50    /// Number of completion tokens reported by the model.
51    pub completion_tokens: Option<i64>,
52    /// Time spent processing the prompt (milliseconds).
53    pub prompt_ms: Option<f64>,
54    /// Time spent generating the response (milliseconds).
55    pub generation_ms: Option<f64>,
56    /// Prompt-processing throughput (tokens/sec). `None` if timings absent.
57    pub prompt_tps: Option<f64>,
58    /// Token-generation throughput (tokens/sec). `None` if timings absent.
59    pub generation_tps: Option<f64>,
60    /// UTC timestamp of this result.
61    pub created_at: DateTime<Utc>,
62}