zai_rs/knowledge/
capacity.rs1use std::sync::Arc;
2
3use super::types::KnowledgeCapacityResponse;
4use crate::client::{
5 endpoints::{ApiBase, EndpointConfig, paths},
6 http::{HttpClient, HttpClientConfig, parse_typed_response},
7};
8
9pub struct KnowledgeCapacityRequest {
11 pub key: String,
13 url: String,
14 endpoint_config: EndpointConfig,
15 api_base: ApiBase,
16 http_config: Arc<HttpClientConfig>,
17 _body: (),
18}
19
20impl KnowledgeCapacityRequest {
21 pub fn new(key: String) -> Self {
23 let endpoint_config = EndpointConfig::default();
24 let api_base = ApiBase::LlmApplication;
25 let url = endpoint_config.url(&api_base, paths::KNOWLEDGE_CAPACITY);
26 Self {
27 key,
28 url,
29 endpoint_config,
30 api_base,
31 http_config: Arc::new(HttpClientConfig::default()),
32 _body: (),
33 }
34 }
35
36 fn rebuild_url(&mut self) {
37 self.url = self
38 .endpoint_config
39 .url(&self.api_base, paths::KNOWLEDGE_CAPACITY);
40 }
41
42 pub fn with_base_url(mut self, base: impl Into<String>) -> Self {
43 self.api_base = ApiBase::Custom(base.into());
44 self.rebuild_url();
45 self
46 }
47
48 pub fn with_endpoint_config(mut self, endpoint_config: EndpointConfig) -> Self {
49 self.endpoint_config = endpoint_config;
50 self.rebuild_url();
51 self
52 }
53
54 pub fn with_http_config(mut self, config: HttpClientConfig) -> Self {
55 self.http_config = Arc::new(config);
56 self
57 }
58
59 pub async fn send(&self) -> crate::ZaiResult<KnowledgeCapacityResponse> {
61 let resp = self.get().await?;
62
63 let parsed = parse_typed_response::<KnowledgeCapacityResponse>(resp).await?;
64
65 Ok(parsed)
66 }
67}
68
69impl HttpClient for KnowledgeCapacityRequest {
70 type Body = ();
71 type ApiUrl = String;
72 type ApiKey = String;
73
74 fn api_url(&self) -> &Self::ApiUrl {
75 &self.url
76 }
77 fn api_key(&self) -> &Self::ApiKey {
78 &self.key
79 }
80 fn body(&self) -> &Self::Body {
81 &self._body
82 }
83
84 fn http_config(&self) -> Arc<HttpClientConfig> {
85 Arc::clone(&self.http_config)
86 }
87}