kernelx_core/models/
config.rs

1use serde_json::Value;
2use std::collections::HashMap;
3
4#[derive(Debug, Clone)]
5pub struct ModelConfig {
6    pub model_id: Option<String>,
7    pub temperature: Option<f32>,
8    pub max_tokens: Option<u32>,
9    pub system_prompt: Option<String>,
10    pub extra: HashMap<String, Value>,
11}
12
13impl Default for ModelConfig {
14    fn default() -> Self {
15        Self {
16            model_id: Some("default".into()),
17            temperature: Some(0.6),
18            max_tokens: Some(200),
19            system_prompt: Some("You are a truthful automaton.".into()),
20            extra: HashMap::new(),
21        }
22    }
23}
24
25impl ModelConfig {
26    pub fn new() -> Self {
27        Self::default()
28    }
29
30    pub fn merge(&self, other: &ModelConfig) -> ModelConfig {
31        ModelConfig {
32            model_id: self.model_id.clone().or(other.model_id.clone()),
33            temperature: other.temperature.or(self.temperature),
34            max_tokens: other.max_tokens.or(self.max_tokens),
35            system_prompt: other
36                .system_prompt
37                .clone()
38                .or_else(|| self.system_prompt.clone()),
39            extra: {
40                let mut merged = self.extra.clone();
41                for (k, v) in &other.extra {
42                    merged.insert(k.clone(), v.clone());
43                }
44                merged
45            },
46        }
47    }
48
49    pub fn with_temperature(mut self, temp: f32) -> Self {
50        self.temperature = Some(temp);
51        self
52    }
53
54    pub fn with_system_prompt(mut self, prompt: impl Into<String>) -> Self {
55        self.system_prompt = Some(prompt.into());
56        self
57    }
58
59    pub fn with_max_tokens(mut self, tokens: u32) -> Self {
60        self.max_tokens = Some(tokens);
61        self
62    }
63}