Skip to main content

deepseek_sdk/
models.rs

1//! Model list API.
2//!
3//! Maps to `GET /models`.
4use crate::DeepSeekClient;
5use crate::DeepSeekError;
6use crate::api_get;
7use serde::Deserialize;
8
9/// Model list response.
10#[derive(Debug, Clone, Eq, PartialEq, Deserialize)]
11pub struct Models {
12    /// Possible values: [`list`]
13    pub object: String,
14    pub data: Vec<ModelInfo>,
15}
16
17/// Model info entry.
18#[derive(Debug, Clone, Eq, PartialEq, Deserialize)]
19pub struct ModelInfo {
20    /// The model identifier, which can be referenced in the API endpoints.
21    pub id: String,
22
23    /// Possible values: [model]
24    ///
25    /// The object type, which is always "model".
26    pub object: String,
27
28    /// The organization that owns the model.
29    pub owned_by: String,
30}
31
32impl Models {
33    /// List available models.
34    pub async fn list(client: DeepSeekClient) -> Result<Self, DeepSeekError> {
35        api_get("/models", client).await
36    }
37}
38
39#[cfg(test)]
40mod tests {
41    use super::*;
42    use crate::DEFAULT_BASE_URL;
43
44    fn get_client() -> DeepSeekClient {
45        DeepSeekClient::new(
46            std::env::var("DEEPSEEK_API").expect("DEEPSEEK_API is not set"),
47            DEFAULT_BASE_URL.clone(),
48        )
49    }
50
51    #[tokio::test]
52    async fn test_list_models() {
53        let client = get_client();
54        let models = Models::list(client).await.unwrap();
55        println!("{:#?}", models);
56        assert_eq!(models.object, "list");
57        assert!(!models.data.is_empty());
58    }
59}