Skip to main content

telos_agent/model/provider/deepseek/
config.rs

1use crate::error::AgentError;
2
3/// Configuration for [`DeepSeekProvider`](crate::DeepSeekProvider).
4#[derive(Clone)]
5pub struct DeepSeekConfig {
6    pub api_key: String,
7    pub model: String,
8    /// Base URL — override to talk to a DeepSeek-compatible service.
9    /// The provider automatically appends `/v1` if it is not present.
10    pub base_url: String,
11}
12
13impl std::fmt::Debug for DeepSeekConfig {
14    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15        f.debug_struct("DeepSeekConfig")
16            .field("api_key", &"[REDACTED]")
17            .field("model", &self.model)
18            .field("base_url", &self.base_url)
19            .finish()
20    }
21}
22
23impl DeepSeekConfig {
24    /// Build a config from an explicit API key and model.
25    pub fn new(api_key: impl Into<String>, model: impl Into<String>) -> Self {
26        Self {
27            api_key: api_key.into(),
28            model: model.into(),
29            base_url: "https://api.deepseek.com".into(),
30        }
31    }
32
33    /// Build a config from `DEEPSEEK_API_KEY` and the given model.
34    ///
35    /// Reads the API key directly from the process environment. Callers that
36    /// want to load a `.env` file should do so explicitly before calling this
37    /// constructor.
38    pub fn from_env(model: impl Into<String>) -> Result<Self, AgentError> {
39        let api_key = std::env::var("DEEPSEEK_API_KEY")
40            .map_err(|_| AgentError::Config("missing DEEPSEEK_API_KEY".into()))?;
41
42        Ok(Self::new(api_key, model))
43    }
44}