use std::collections::HashMap;
#[derive(Debug, Clone)]
pub struct LlmConfig {
pub base_url: String,
pub api_key: String,
pub model: String,
pub max_tokens: u32,
pub extra_headers: HashMap<String, String>,
pub use_responses_api: bool,
pub use_gemini_native_api: bool,
}
impl LlmConfig {
pub fn new(base_url: &str, model: &str, api_key: &str) -> Self {
Self {
base_url: base_url.to_string(),
api_key: api_key.to_string(),
model: model.to_string(),
max_tokens: 4096,
extra_headers: HashMap::new(),
use_responses_api: false,
use_gemini_native_api: false,
}
}
pub fn from_env(base_url: &str, model: &str, env_var: &str) -> Option<Self> {
std::env::var(env_var)
.ok()
.map(|key| Self::new(base_url, model, &key))
}
pub fn with_max_tokens(mut self, max_tokens: u32) -> Self {
self.max_tokens = max_tokens;
self
}
pub fn with_header(mut self, key: &str, value: &str) -> Self {
self.extra_headers
.insert(key.to_string(), value.to_string());
self
}
pub fn with_responses_api(mut self) -> Self {
self.use_responses_api = true;
self
}
pub fn with_gemini_native_api(mut self) -> Self {
self.use_gemini_native_api = true;
self
}
}