gglib_core/domain/server_config.rs
1//! Server-level default configuration for models.
2//!
3//! This module defines [`ServerConfig`], which stores per-model server
4//! parameters that override global settings but can themselves be overridden
5//! at request time.
6//!
7//! # Fallback Chain
8//!
9//! Parameters are resolved in strict priority order:
10//!
11//! 1. Runtime request / CLI flag (highest priority)
12//! 2. Model `server_defaults` (from DB, stored as JSON)
13//! 3. Global app setting, when the user set one
14//! 4. Fitted to this machine
15//! 5. Hardcoded default (lowest priority)
16
17use serde::{Deserialize, Serialize};
18
19/// Server-level defaults for a specific model.
20///
21/// Stores per-model server configuration parameters that override global
22/// settings but can themselves be overridden at request time. This is part
23/// of the 5-level fallback chain:
24///
25/// 1. Runtime request / CLI flag (highest priority)
26/// 2. Model `server_defaults` (from DB, stored as JSON in `server_defaults` column)
27/// 3. Global app setting, when the user set one
28/// 4. Fitted to this machine
29/// 5. Hardcoded default (lowest priority)
30///
31/// All fields are optional to support partial configuration.
32///
33/// # Examples
34///
35/// ```rust
36/// use gglib_core::domain::ServerConfig;
37///
38/// // Override only the context length for a long-context model
39/// let config = ServerConfig {
40/// context_length: Some(32768),
41/// };
42/// ```
43#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
44#[cfg_attr(feature = "ts-bindings", derive(ts_rs::TS), ts(export))]
45#[serde(rename_all = "camelCase")]
46pub struct ServerConfig {
47 /// Context length (number of tokens) for the model server.
48 ///
49 /// Controls the maximum context window the server will use.
50 /// This field is level 2 of the chain above, so `None` falls through to
51 /// levels 3 through 5: the global setting, a context fitted to this
52 /// machine, and finally the built-in floor — which is where a host whose
53 /// device gglib cannot read ends up. Common values: 8192, 32768, 131072.
54 pub context_length: Option<usize>,
55}