zai_rs/knowledge/
document_image_list.rs1use std::sync::Arc;
2
3use super::types::DocumentImageListResponse;
4use crate::client::{
5 endpoints::{ApiBase, EndpointConfig, join_url, paths},
6 http::{HttpClient, HttpClientConfig, parse_typed_response, send_empty_request},
7};
8
9pub struct DocumentImageListRequest {
11 pub key: String,
13 url: String,
14 endpoint_config: EndpointConfig,
15 api_base: ApiBase,
16 document_id: String,
17 http_config: Arc<HttpClientConfig>,
18 _body: (),
19}
20
21impl DocumentImageListRequest {
22 pub fn new(key: String, document_id: impl AsRef<str>) -> Self {
24 let document_id = document_id.as_ref().to_string();
25 let endpoint_config = EndpointConfig::default();
26 let api_base = ApiBase::LlmApplication;
27 let url = endpoint_config.url(
28 &api_base,
29 &join_url(paths::DOCUMENT_SLICE_IMAGE_LIST, &document_id),
30 );
31 Self {
32 key,
33 url,
34 endpoint_config,
35 api_base,
36 document_id,
37 http_config: Arc::new(HttpClientConfig::default()),
38 _body: (),
39 }
40 }
41
42 fn rebuild_url(&mut self) {
43 self.url = self.endpoint_config.url(
44 &self.api_base,
45 &join_url(paths::DOCUMENT_SLICE_IMAGE_LIST, &self.document_id),
46 );
47 }
48
49 pub fn with_base_url(mut self, base_url: impl Into<String>) -> Self {
50 self.api_base = ApiBase::Custom(base_url.into());
51 self.rebuild_url();
52 self
53 }
54
55 pub fn with_endpoint_config(mut self, endpoint_config: EndpointConfig) -> Self {
56 self.endpoint_config = endpoint_config;
57 self.rebuild_url();
58 self
59 }
60
61 pub fn with_http_config(mut self, config: HttpClientConfig) -> Self {
62 self.http_config = Arc::new(config);
63 self
64 }
65
66 pub async fn send(&self) -> crate::ZaiResult<DocumentImageListResponse> {
68 let resp: reqwest::Response = self.post().await?;
69 parse_typed_response::<DocumentImageListResponse>(resp).await
70 }
71}
72
73impl HttpClient for DocumentImageListRequest {
74 type Body = (); type ApiUrl = String;
76 type ApiKey = String;
77
78 fn api_url(&self) -> &Self::ApiUrl {
79 &self.url
80 }
81 fn api_key(&self) -> &Self::ApiKey {
82 &self.key
83 }
84 fn body(&self) -> &Self::Body {
85 &self._body
86 }
87
88 fn post(
90 &self,
91 ) -> impl std::future::Future<Output = crate::ZaiResult<reqwest::Response>> + Send {
92 let url = self.url.clone();
93 let key = self.key.clone();
94 let config = self.http_config.clone();
95 async move { send_empty_request(reqwest::Method::POST, url, key, config).await }
96 }
97
98 fn http_config(&self) -> Arc<HttpClientConfig> {
99 self.http_config.clone()
100 }
101}