zai_rs/knowledge/
document_retrieve.rs

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