use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UniversalConfig {
pub model: String,
pub api_key: Option<String>,
pub base_url: Option<String>,
pub max_tokens: Option<u32>,
pub temperature: Option<f32>,
pub top_p: Option<f32>,
pub top_k: Option<u32>,
pub system: Option<String>,
pub timeout_seconds: Option<u64>,
pub resilient: Option<bool>,
pub resilient_attempts: Option<usize>,
}
impl Default for UniversalConfig {
fn default() -> Self {
Self {
model: String::new(),
api_key: None,
base_url: None,
max_tokens: Some(4096),
temperature: None,
top_p: None,
top_k: None,
system: None,
timeout_seconds: None,
resilient: None,
resilient_attempts: None,
}
}
}
impl UniversalConfig {
pub fn new(model: impl Into<String>) -> Self {
Self {
model: model.into(),
..Default::default()
}
}
pub fn with_api_key(mut self, api_key: impl Into<String>) -> Self {
self.api_key = Some(api_key.into());
self
}
pub fn with_base_url(mut self, url: impl Into<String>) -> Self {
self.base_url = Some(url.into());
self
}
pub fn with_max_tokens(mut self, tokens: u32) -> Self {
self.max_tokens = Some(tokens);
self
}
pub fn with_temperature(mut self, temp: f32) -> Self {
self.temperature = Some(temp);
self
}
pub fn with_system(mut self, prompt: impl Into<String>) -> Self {
self.system = Some(prompt.into());
self
}
pub fn with_resilience(mut self, attempts: usize) -> Self {
self.resilient = Some(true);
self.resilient_attempts = Some(attempts);
self
}
pub fn provider(&self) -> Option<&str> {
self.model.split("::").next()
}
pub fn model_name(&self) -> &str {
self.model.split("::").nth(1).unwrap_or(&self.model)
}
}