Skip to main content

systemprompt_models/ai/
models.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, Hash)]
5pub struct ToolModelConfig {
6    #[serde(skip_serializing_if = "Option::is_none")]
7    pub provider: Option<String>,
8    #[serde(skip_serializing_if = "Option::is_none")]
9    pub model: Option<String>,
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub max_output_tokens: Option<u32>,
12}
13
14impl ToolModelConfig {
15    pub fn new(provider: impl Into<String>, model: impl Into<String>) -> Self {
16        Self {
17            provider: Some(provider.into()),
18            model: Some(model.into()),
19            max_output_tokens: None,
20        }
21    }
22
23    pub const fn with_max_output_tokens(mut self, tokens: u32) -> Self {
24        self.max_output_tokens = Some(tokens);
25        self
26    }
27
28    pub const fn is_empty(&self) -> bool {
29        self.provider.is_none() && self.model.is_none() && self.max_output_tokens.is_none()
30    }
31
32    pub fn merge_with(&self, other: &Self) -> Self {
33        Self {
34            provider: other.provider.as_ref().or(self.provider.as_ref()).cloned(),
35            model: other.model.as_ref().or(self.model.as_ref()).cloned(),
36            max_output_tokens: other.max_output_tokens.or(self.max_output_tokens),
37        }
38    }
39}
40
41pub type ToolModelOverrides = HashMap<String, HashMap<String, ToolModelConfig>>;
42
43#[derive(Debug, Clone, Serialize, Deserialize)]
44pub struct ModelConfig {
45    // JSON: external LLM model identifier (e.g. "claude-opus-4-6")
46    pub id: String,
47    pub max_tokens: u32,
48    pub supports_tools: bool,
49    #[serde(default)]
50    pub cost_per_1k_tokens: f32,
51}
52
53impl ModelConfig {
54    pub fn new(id: impl Into<String>, max_tokens: u32, supports_tools: bool) -> Self {
55        Self {
56            id: id.into(),
57            max_tokens,
58            supports_tools,
59            cost_per_1k_tokens: 0.0,
60        }
61    }
62
63    pub const fn with_cost(mut self, cost: f32) -> Self {
64        self.cost_per_1k_tokens = cost;
65        self
66    }
67}