From a4a861ab58414a9b5ed12d3f969c5415dcb4bf40 Mon Sep 17 00:00:00 2001 From: fkDead Date: Wed, 11 Nov 2026 20:20:47 +0100 Subject: [PATCH] capri-llm: add sections module --- crates/capri-llm/src/sections.rs | 104 +++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 crates/capri-llm/src/sections.rs diff --git a/crates/capri-llm/src/sections.rs b/crates/capri-llm/src/sections.rs new file mode 100644 index 0000000..592ea88 --- /dev/null +++ b/crates/capri-llm/src/sections.rs @@ -0,0 +1,104 @@ +//! Inference settings stored in `settings.json` `sections` (Capri `core.json` keys that `Settings` +//! does not carry, the API selection, the startup policy and the request router). +use capri_core::Section; +use serde::{Deserialize, Serialize}; + +use crate::openai::ApiConnection; + +/// Local model options beyond `Settings` (`model`, `upstreamModel`, `contextTokens`, `keepAlive`, +/// `cpuThreads`, `acceleration`, `temperature`, `repeatLastN` stay there). +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[serde(default, rename_all = "camelCase")] +pub struct InferenceSection { + /// Memory embeddings, always on the CPU. + pub embedding_model: String, + pub preload_models: bool, + /// `LLAMA_ARG_THINK_BUDGET = max(value, 4096)` (inert in Capri 1.0.4, kept for compatibility). + pub reasoning_budget: u32, + /// `off` | `low`: thinking default for the profile (ordinary turns send thinking off). + pub thinking_default: String, + /// No language model prepared yet: local mode refuses to chat. + pub model_setup_required: bool, + /// Declared capabilities of the local model (`tools`, `vision`, `thinking`); `None` = all (Qwen). + pub model_capabilities: Option>, + /// Largest context the local model supports; `None` = 262144. + pub model_context_limit: Option, + /// Catalog id of the local model (`desktop`, `gemma4-e2b`, `hf-<24 hex>`…). + pub resource_profile: Option, + /// Minimum Ollama version (`ollamaVersion`). + pub min_ollama_version: String, + /// Language model device: `auto`, `cpu`, `cuda:`, `rocm:`, `vulkan:`. + pub device: String, + /// API mode does not load, prime or keep the local chat model. + pub skip_local_model_on_api: bool, +} + +impl Default for InferenceSection { + fn default() -> Self { + Self { + embedding_model: "capri-embed:latest".into(), + preload_models: false, + reasoning_budget: 64, + thinking_default: "low".into(), + model_setup_required: false, + model_capabilities: None, + model_context_limit: None, + resource_profile: None, + min_ollama_version: "0.40.10".into(), + device: "auto".into(), + skip_local_model_on_api: true, + } + } +} + +impl Section for InferenceSection { + const NAME: &'static str = "inference"; +} + +/// External API providers: saved connections (keys in the secret store) and the active one. +#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq)] +#[serde(default, rename_all = "camelCase")] +pub struct ApiSection { + /// API mode selected (false = local model). + pub enabled: bool, + /// Id of the active connection. + pub active: Option, + pub connections: Vec, +} + +impl Section for ApiSection { + const NAME: &'static str = "api"; +} + +impl ApiSection { + pub const MAX_CONNECTIONS: usize = 20; + + pub fn active_connection(&self) -> Option<&ApiConnection> { + self.enabled.then_some(())?; + let id = self.active.as_deref()?; + self.connections.iter().find(|c| c.id == id) + } +} + +/// Request router (Capri `config/request-router.json`). +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[serde(default, rename_all = "camelCase")] +pub struct RouterSection { + pub enabled: bool, + /// Classification budget, 25…250 ms. + pub timeout_ms: u64, + /// CPU embedding alias used for routing. + pub model: String, + /// Ollama library model the alias is created from (MiniLM-L6-v2, 384 dims). + pub base_model: String, +} + +impl Default for RouterSection { + fn default() -> Self { + Self { enabled: true, timeout_ms: 150, model: "capri-router:latest".into(), base_model: "all-minilm:l6-v2".into() } + } +} + +impl Section for RouterSection { + const NAME: &'static str = "router"; +}