* worker.rs (1271 lines, 1120 of them tests) is 149 lines; the supervisor tests are worker/tests.rs (shared fixtures) and
worker/tests/{deadlines,handshake,generation,restart,lifecycle,reasoning}.rs. The test names are unchanged; their path
gains the topic module (worker::tests::restart::..., see scripts/dev/test-outcomes.py compare: 23 MOVED, outcomes equal).
* vision.rs 402 -> 120 lines (tests are vision/tests.rs, same test ids); prometheus.rs 441 -> 50 (the series table is
prometheus/series.rs); service_install.rs 436 -> 30 (the unix half is service_install/unix.rs and unix/tests.rs, same ids).
* config: Config::load_with_path (430 lines in one function) hands its limits, engine-worker and MCP sections to
config/methods/load_sections.rs; the same checks run in the same order with the same messages.
* mcp, request_log, vision, worker, config: impl_*/note_*/check_* file names are now hub.rs, server.rs, stdio_transport.rs,
http_transport.rs, parse_config.rs, obs_handle.rs, engine_counters.rs, encoder.rs, cleanup.rs, generation_result.rs, ...
Public paths are unchanged (the modules re-export with glob as before).
Architecture gate: five oversize entries leave the baseline (worker.rs, vision.rs, prometheus.rs, service_install.rs,
config impl_config_2_2.rs); no number rose.
174 lines
6.7 KiB
Rust
174 lines
6.7 KiB
Rust
use std::{
|
|
env,
|
|
ffi::OsString,
|
|
fs,
|
|
net::SocketAddr,
|
|
path::{Path, PathBuf},
|
|
time::Duration,
|
|
};
|
|
|
|
use serde::Deserialize;
|
|
|
|
use crate::worker::WorkerConfig;
|
|
|
|
pub struct Config {
|
|
pub queue_timeout: Option<Duration>,
|
|
pub response_history_dir: Option<PathBuf>,
|
|
pub mtp_pack: Option<PathBuf>,
|
|
pub assets: Vec<crate::asset_bundle::AssetBundle>,
|
|
pub native_model: Option<crate::native_model::NativeModel>,
|
|
pub gpu_requirement: Option<crate::doctor::GpuRequirement>,
|
|
pub cuda_memory: Option<crate::cuda_memory::Policy>,
|
|
host_checked: bool,
|
|
pub engine_probe: bool,
|
|
pub shutdown_grace: Duration,
|
|
pub max_in_flight_requests: usize,
|
|
pub api_key: Option<std::sync::Arc<crate::auth::ApiKey>>,
|
|
pub bind: SocketAddr,
|
|
pub model: Option<String>,
|
|
pub worker: Option<WorkerConfig>,
|
|
/// Serve in front of a running `leleka-inference` instead of a stdio engine (`runtime` block).
|
|
pub runtime: Option<crate::runtime_config::RuntimeBackend>,
|
|
/// Further workers with the same timeouts, served together with `worker` through [`crate::pool`] (experimental).
|
|
pub extra_workers: Vec<WorkerConfig>,
|
|
/// What the gpt-oss system message says about the date (see [`crate::responses::PromptDate`]).
|
|
pub prompt_date: crate::responses::PromptDate,
|
|
pub tokenizer_dir: Option<PathBuf>,
|
|
/// A gpt-oss GGUF file: serve the gpt-oss family, taking the tokenizer from its vocabulary.
|
|
pub gptoss_gguf: Option<PathBuf>,
|
|
/// Other names the model answers to (`aliases`).
|
|
pub aliases: Vec<String>,
|
|
/// Browser pages of these origins may call `/v1/*` (`cors_origins`; `"*"` allowed).
|
|
pub cors_origins: Vec<String>,
|
|
/// Origins that count as this server's own page (`trusted_origins`; no wildcard).
|
|
pub trusted_origins: Vec<String>,
|
|
/// `api_monitor`: keep the last requests' prompts and answers in memory for `GET /api/requests` (off by default).
|
|
pub api_monitor: bool,
|
|
/// EXPERIMENTAL `tool_call_recovery` (off by default): read a declared tool's call written in a drifted form as the call.
|
|
/// See `docs/api-contract.md`, "Tool-call recovery (experimental)".
|
|
pub tool_call_recovery: bool,
|
|
/// The `sampling` block: defaults for what a request leaves out.
|
|
pub sampling: leleka_serving_policy::shared::ConfigSampling,
|
|
/// `reasoning_budget_tokens`: the default thinking budget (0: none).
|
|
pub reasoning_budget_tokens: Option<serde_json::Value>,
|
|
/// Where the Chat settings shared with every client are kept between starts.
|
|
pub shared_settings_file: Option<PathBuf>,
|
|
/// Unload the engine after this long without requests (`engine.idle_unload_s`).
|
|
pub idle_unload: Option<Duration>,
|
|
/// MCP servers (`mcp_servers`, `mcpServers`, `mcp_config_file`); empty when there are none.
|
|
pub mcp_servers: std::collections::BTreeMap<String, serde_json::Map<String, serde_json::Value>>,
|
|
/// The `mcp` block: timeouts and caps.
|
|
pub mcp_settings: crate::mcp::Settings,
|
|
/// The image encoder's configuration (started by `serve` before the engine).
|
|
pub vision: Option<crate::vision::VisionConfig>,
|
|
}
|
|
|
|
#[derive(Default, Deserialize)]
|
|
#[serde(deny_unknown_fields)]
|
|
struct FileConfig {
|
|
queue_timeout_s: Option<u64>,
|
|
/// `utc` (default), `none` (experimental: no date line, give the date as a tool) or `YYYY-MM-DD`.
|
|
prompt_date: Option<String>,
|
|
mtp_pack: Option<PathBuf>,
|
|
response_history_dir: Option<PathBuf>,
|
|
#[serde(default)]
|
|
assets: Vec<crate::asset_bundle::AssetBundle>,
|
|
native_model: Option<crate::native_model::NativeModel>,
|
|
gpu_requirement: Option<crate::doctor::GpuRequirement>,
|
|
cuda_memory: Option<crate::cuda_memory::Policy>,
|
|
#[serde(default)]
|
|
engine_probe: bool,
|
|
shutdown_grace_s: Option<u64>,
|
|
max_in_flight_requests: Option<usize>,
|
|
api_key_file: Option<PathBuf>,
|
|
bind: Option<String>,
|
|
model: Option<String>,
|
|
engine: Option<FileEngine>,
|
|
runtime: Option<crate::runtime_config::FileRuntime>,
|
|
aliases: Option<serde_json::Value>,
|
|
cors_origins: Option<serde_json::Value>,
|
|
trusted_origins: Option<serde_json::Value>,
|
|
api_monitor: Option<bool>,
|
|
tool_call_recovery: Option<bool>,
|
|
sampling: Option<serde_json::Value>,
|
|
reasoning_budget_tokens: Option<serde_json::Value>,
|
|
shared_settings_file: Option<PathBuf>,
|
|
mcp_servers: Option<serde_json::Value>,
|
|
#[serde(rename = "mcpServers")]
|
|
mcp_servers_desktop: Option<serde_json::Value>,
|
|
mcp_config_file: Option<PathBuf>,
|
|
mcp: Option<serde_json::Value>,
|
|
/// The image encoder (`strata-vision`): without it the server cannot read pictures.
|
|
vision: Option<crate::vision::VisionConfig>,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
#[serde(deny_unknown_fields)]
|
|
struct FileEngine {
|
|
executable: String,
|
|
#[serde(default)]
|
|
args: Vec<String>,
|
|
startup_timeout_s: Option<u64>,
|
|
generation_timeout_s: Option<u64>,
|
|
max_restarts: Option<u32>,
|
|
tokenizer_dir: Option<PathBuf>,
|
|
gptoss_gguf: Option<PathBuf>,
|
|
/// Further workers (executable and arguments) served together with this one, one request each at a time.
|
|
#[serde(default)]
|
|
extra_workers: Vec<FileExtraWorker>,
|
|
/// Start unloaded; the first request loads the engine.
|
|
#[serde(default)]
|
|
lazy_load: bool,
|
|
/// Unload after this many idle seconds so other programs can use the GPU.
|
|
idle_unload_s: Option<f64>,
|
|
/// Reload only when this much VRAM is free (MiB).
|
|
min_free_vram_mib: Option<u64>,
|
|
/// Command run before every reload and restart (a shell line or an argv list).
|
|
before_load: Option<crate::worker::BeforeLoad>,
|
|
/// No engine line for this long during a request ends it (the stall watchdog).
|
|
stall_timeout_s: Option<u64>,
|
|
/// A control vector on the residual stream (steering); requests switch it per request.
|
|
control_vector: Option<ControlVector>,
|
|
}
|
|
|
|
/// `--control-vector-scaled`, `--cvec-mode`, `--cvec-dir`, `--control-vector-layer-range`.
|
|
#[derive(Deserialize)]
|
|
#[serde(deny_unknown_fields)]
|
|
struct ControlVector {
|
|
files: Vec<ControlVectorFile>,
|
|
/// `add` (default) or `project`.
|
|
mode: Option<String>,
|
|
/// `per-layer` (default) or `single:L` (project mode).
|
|
dir: Option<String>,
|
|
/// First and last steered layer, inclusive.
|
|
layer_range: Option<[i32; 2]>,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
#[serde(deny_unknown_fields)]
|
|
struct FileExtraWorker {
|
|
executable: String,
|
|
#[serde(default)]
|
|
args: Vec<String>,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
#[serde(deny_unknown_fields)]
|
|
struct ControlVectorFile {
|
|
path: PathBuf,
|
|
scale: f32,
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests;
|
|
|
|
mod control_vector;
|
|
#[allow(unused_imports)]
|
|
pub use control_vector::*;
|
|
mod methods;
|
|
#[allow(unused_imports)]
|
|
pub use methods::*;
|
|
mod optional_env;
|
|
#[allow(unused_imports)]
|
|
pub use optional_env::*;
|