walrus_model/config.rs
1//! Provider configuration.
2//!
3//! `ProviderConfig` and `ApiStandard` are defined in wcore and re-exported here.
4//! `Loader` selects which mistralrs builder to use for local models.
5
6use compact_str::CompactString;
7use serde::{Deserialize, Serialize};
8use std::collections::BTreeMap;
9
10pub use wcore::config::provider::{ApiStandard, ProviderConfig};
11
12/// Selects which mistralrs model builder to use for local inference.
13///
14/// Defaults to `Text` when omitted in config.
15#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default)]
16#[serde(rename_all = "snake_case")]
17pub enum Loader {
18 /// `TextModelBuilder` — standard text models.
19 #[default]
20 Text,
21 /// `GgufModelBuilder` — GGUF quantized models.
22 Gguf,
23 /// `VisionModelBuilder` — vision-language models.
24 Vision,
25}
26
27/// Custom HuggingFace model configuration for local inference.
28///
29/// Allows users to run any HuggingFace model not in the built-in registry.
30/// Memory and quantization are auto-selected at runtime based on system RAM.
31#[derive(Debug, Clone, Serialize, Deserialize)]
32pub struct HfModelConfig {
33 /// HuggingFace repository ID (e.g. `"myorg/MyModel-7B-GGUF"`).
34 pub model_id: String,
35 /// Which mistralrs builder to use.
36 #[serde(default)]
37 pub loader: Loader,
38 /// Explicit GGUF filename (required for GGUF models without a standard
39 /// naming convention).
40 #[serde(default, skip_serializing_if = "Option::is_none")]
41 pub gguf_file: Option<String>,
42 /// Custom chat template override.
43 #[serde(default, skip_serializing_if = "Option::is_none")]
44 pub chat_template: Option<String>,
45}
46
47/// Model provider configuration for the daemon.
48///
49/// Remote providers are configured in `providers`. Local models come from the
50/// built-in registry or from user-defined `models`. The active model name
51/// lives in `[walrus].model`.
52#[derive(Debug, Clone, Serialize, Deserialize, Default)]
53pub struct ModelConfig {
54 /// Optional embedding model
55 #[serde(default, skip_serializing_if = "Option::is_none")]
56 pub embedding: Option<CompactString>,
57 /// Remote providers (local models come from the built-in registry)
58 #[serde(default)]
59 pub providers: BTreeMap<CompactString, ProviderConfig>,
60 /// Custom HuggingFace models for local inference
61 #[serde(default)]
62 pub models: BTreeMap<CompactString, HfModelConfig>,
63}
64
65// MemoryThreshold is generated by build.rs from registry TOML files.
66include!(concat!(env!("OUT_DIR"), "/quantization.rs"));