zai_rs/knowledge/
document_image_list.rs1use super::types::DocumentImageListResponse;
2use crate::client::http::HttpClient;
3
4pub struct DocumentImageListRequest {
6 pub key: String,
8 url: String,
9}
10
11impl DocumentImageListRequest {
12 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/slice/image_list/{}",
16 document_id.as_ref()
17 );
18 Self { key, url }
19 }
20
21 pub async fn send(&self) -> crate::ZaiResult<DocumentImageListResponse> {
23 let resp: reqwest::Response = self.post().await?;
24
25 let parsed = resp.json::<DocumentImageListResponse>().await?;
26
27 Ok(parsed)
28 }
29}
30
31impl HttpClient for DocumentImageListRequest {
32 type Body = (); type ApiUrl = String;
34 type ApiKey = String;
35
36 fn api_url(&self) -> &Self::ApiUrl {
37 &self.url
38 }
39 fn api_key(&self) -> &Self::ApiKey {
40 &self.key
41 }
42 fn body(&self) -> &Self::Body {
43 &()
44 }
45
46 fn post(
48 &self,
49 ) -> impl std::future::Future<Output = crate::ZaiResult<reqwest::Response>> + Send {
50 let url = self.url.clone();
51 let key = self.key.clone();
52 async move {
53 let resp = reqwest::Client::new()
54 .post(url)
55 .bearer_auth(key)
56 .send()
57 .await?;
58
59 let status = resp.status();
60 if status.is_success() {
61 return Ok(resp);
62 }
63
64 let text = resp.text().await.unwrap_or_default();
66 #[derive(serde::Deserialize)]
67 struct ErrEnv {
68 error: ErrObj,
69 }
70 #[derive(serde::Deserialize)]
71 struct ErrObj {
72 _code: serde_json::Value,
73 message: String,
74 }
75
76 if let Ok(parsed) = serde_json::from_str::<ErrEnv>(&text) {
77 return Err(crate::client::error::ZaiError::from_api_response(
78 status.as_u16(),
79 0,
80 parsed.error.message,
81 ));
82 }
83
84 Err(crate::client::error::ZaiError::from_api_response(
85 status.as_u16(),
86 0,
87 text,
88 ))
89 }
90 }
91}