105 lines
3.8 KiB
Rust
105 lines
3.8 KiB
Rust
//! 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<Vec<String>>,
|
|
/// Largest context the local model supports; `None` = 262144.
|
|
pub model_context_limit: Option<u32>,
|
|
/// Catalog id of the local model (`desktop`, `gemma4-e2b`, `hf-<24 hex>`…).
|
|
pub resource_profile: Option<String>,
|
|
/// Minimum Ollama version (`ollamaVersion`).
|
|
pub min_ollama_version: String,
|
|
/// Language model device: `auto`, `cpu`, `cuda:<GPU uuid>`, `rocm:<ordinal>`, `vulkan:<ordinal>`.
|
|
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<String>,
|
|
pub connections: Vec<ApiConnection>,
|
|
}
|
|
|
|
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";
|
|
}
|