use serde::{Deserialize, Serialize};
pub const DEEPSEEK_API_BASE: &str = "https://api.deepseek.com";
pub const DEEPSEEK_BETA_API_BASE: &str = "https://api.deepseek.com/beta";
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeepSeekConfig {
pub api_key: String,
pub model: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub base_url: Option<String>,
#[serde(default)]
pub thinking_enabled: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub max_tokens: Option<u32>,
}
impl Default for DeepSeekConfig {
fn default() -> Self {
Self {
api_key: String::new(),
model: "deepseek-chat".to_string(),
base_url: None,
thinking_enabled: false,
max_tokens: None,
}
}
}
impl DeepSeekConfig {
pub fn new(api_key: impl Into<String>, model: impl Into<String>) -> Self {
Self { api_key: api_key.into(), model: model.into(), ..Default::default() }
}
pub fn chat(api_key: impl Into<String>) -> Self {
Self::new(api_key, "deepseek-chat")
}
pub fn reasoner(api_key: impl Into<String>) -> Self {
Self {
api_key: api_key.into(),
model: "deepseek-reasoner".to_string(),
thinking_enabled: true,
max_tokens: Some(8192),
..Default::default()
}
}
pub fn with_thinking(mut self, enabled: bool) -> Self {
self.thinking_enabled = enabled;
self
}
pub fn with_max_tokens(mut self, max_tokens: u32) -> Self {
self.max_tokens = Some(max_tokens);
self
}
pub fn with_base_url(mut self, base_url: impl Into<String>) -> Self {
self.base_url = Some(base_url.into());
self
}
pub fn effective_base_url(&self) -> &str {
self.base_url.as_deref().unwrap_or(DEEPSEEK_API_BASE)
}
}