zai_rs/knowledge/
retrieve.rs

1use super::types::KnowledgeDetailResponse;
2use crate::client::http::HttpClient;
3
4/// Knowledge detail request (GET /llm-application/open/knowledge/{id})
5pub struct KnowledgeRetrieveRequest {
6    /// Bearer API key
7    pub key: String,
8    url: String,
9    _body: (),
10}
11
12impl KnowledgeRetrieveRequest {
13    /// Build a retrieve request with id
14    pub fn new(key: String, id: impl AsRef<str>) -> Self {
15        let url = format!(
16            "https://open.bigmodel.cn/api/llm-application/open/knowledge/{}",
17            id.as_ref()
18        );
19        Self {
20            key,
21            url,
22            _body: (),
23        }
24    }
25
26    /// Send and parse typed response
27    pub async fn send(&self) -> anyhow::Result<KnowledgeDetailResponse> {
28        let resp = self.get().await?;
29        let parsed = resp.json::<KnowledgeDetailResponse>().await?;
30        Ok(parsed)
31    }
32}
33
34impl HttpClient for KnowledgeRetrieveRequest {
35    type Body = ();
36    type ApiUrl = String;
37    type ApiKey = String;
38
39    fn api_url(&self) -> &Self::ApiUrl {
40        &self.url
41    }
42    fn api_key(&self) -> &Self::ApiKey {
43        &self.key
44    }
45    fn body(&self) -> &Self::Body {
46        &self._body
47    }
48}
49
50/// Alias for symmetry with other modules
51pub type KnowledgeRetrieveResponse = KnowledgeDetailResponse;