zai_rs/knowledge/
delete.rs1use std::sync::Arc;
2
3use crate::client::{
4 endpoints::{ApiBase, EndpointConfig, join_url, paths},
5 http::{HttpClient, HttpClientConfig, parse_typed_response},
6};
7
8pub struct KnowledgeDeleteRequest {
10 pub key: String,
12 url: String,
13 endpoint_config: EndpointConfig,
14 api_base: ApiBase,
15 id: String,
16 http_config: Arc<HttpClientConfig>,
17 _body: (),
18}
19
20impl KnowledgeDeleteRequest {
21 pub fn new(key: String, id: impl AsRef<str>) -> Self {
23 let id = id.as_ref().to_string();
24 let endpoint_config = EndpointConfig::default();
25 let api_base = ApiBase::LlmApplication;
26 let url = endpoint_config.url(&api_base, &join_url(paths::KNOWLEDGE, &id));
27 Self {
28 key,
29 url,
30 endpoint_config,
31 api_base,
32 id,
33 http_config: Arc::new(HttpClientConfig::default()),
34 _body: (),
35 }
36 }
37
38 fn rebuild_url(&mut self) {
39 self.url = self
40 .endpoint_config
41 .url(&self.api_base, &join_url(paths::KNOWLEDGE, &self.id));
42 }
43
44 pub fn with_base_url(mut self, base_url: impl Into<String>) -> Self {
45 self.api_base = ApiBase::Custom(base_url.into());
46 self.rebuild_url();
47 self
48 }
49
50 pub fn with_endpoint_config(mut self, endpoint_config: EndpointConfig) -> Self {
51 self.endpoint_config = endpoint_config;
52 self.rebuild_url();
53 self
54 }
55
56 pub fn with_http_config(mut self, config: HttpClientConfig) -> Self {
57 self.http_config = Arc::new(config);
58 self
59 }
60
61 pub fn delete(
62 &self,
63 ) -> impl std::future::Future<Output = crate::ZaiResult<reqwest::Response>> + Send {
64 HttpClient::delete(self)
65 }
66
67 pub async fn send(&self) -> crate::ZaiResult<KnowledgeDeleteResponse> {
69 let resp = self.delete().await?;
70 parse_typed_response::<KnowledgeDeleteResponse>(resp).await
71 }
72}
73
74impl HttpClient for KnowledgeDeleteRequest {
75 type Body = ();
76 type ApiUrl = String;
77 type ApiKey = String;
78
79 fn api_url(&self) -> &Self::ApiUrl {
80 &self.url
81 }
82 fn api_key(&self) -> &Self::ApiKey {
83 &self.key
84 }
85 fn body(&self) -> &Self::Body {
86 &self._body
87 }
88
89 fn http_config(&self) -> Arc<HttpClientConfig> {
90 self.http_config.clone()
91 }
92}
93
94#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, validator::Validate)]
96pub struct KnowledgeDeleteResponse {
97 #[serde(skip_serializing_if = "Option::is_none")]
98 pub code: Option<i64>,
99 #[serde(skip_serializing_if = "Option::is_none")]
100 pub message: Option<String>,
101 #[serde(skip_serializing_if = "Option::is_none")]
102 pub timestamp: Option<u64>,
103}