blackman_client/apis/
semantic_cache_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetConfigError {
22 Status401(),
23 Status500(),
24 UnknownValue(serde_json::Value),
25}
26
27#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum GetStatsError {
31 Status401(),
32 Status500(),
33 UnknownValue(serde_json::Value),
34}
35
36#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum InvalidateAllError {
40 Status401(),
41 Status500(),
42 Status503(),
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum UpdateConfigError {
50 Status400(),
51 Status401(),
52 Status500(),
53 UnknownValue(serde_json::Value),
54}
55
56
57pub async fn get_config(configuration: &configuration::Configuration, ) -> Result<models::SemanticCacheConfig, Error<GetConfigError>> {
58
59 let uri_str = format!("{}/v1/semantic-cache/config", configuration.base_path);
60 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
61
62 if let Some(ref user_agent) = configuration.user_agent {
63 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
64 }
65 if let Some(ref token) = configuration.bearer_access_token {
66 req_builder = req_builder.bearer_auth(token.to_owned());
67 };
68
69 let req = req_builder.build()?;
70 let resp = configuration.client.execute(req).await?;
71
72 let status = resp.status();
73 let content_type = resp
74 .headers()
75 .get("content-type")
76 .and_then(|v| v.to_str().ok())
77 .unwrap_or("application/octet-stream");
78 let content_type = super::ContentType::from(content_type);
79
80 if !status.is_client_error() && !status.is_server_error() {
81 let content = resp.text().await?;
82 match content_type {
83 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
84 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SemanticCacheConfig`"))),
85 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SemanticCacheConfig`")))),
86 }
87 } else {
88 let content = resp.text().await?;
89 let entity: Option<GetConfigError> = serde_json::from_str(&content).ok();
90 Err(Error::ResponseError(ResponseContent { status, content, entity }))
91 }
92}
93
94pub async fn get_stats(configuration: &configuration::Configuration, ) -> Result<models::SemanticCacheStats, Error<GetStatsError>> {
95
96 let uri_str = format!("{}/v1/semantic-cache/stats", configuration.base_path);
97 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
98
99 if let Some(ref user_agent) = configuration.user_agent {
100 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
101 }
102 if let Some(ref token) = configuration.bearer_access_token {
103 req_builder = req_builder.bearer_auth(token.to_owned());
104 };
105
106 let req = req_builder.build()?;
107 let resp = configuration.client.execute(req).await?;
108
109 let status = resp.status();
110 let content_type = resp
111 .headers()
112 .get("content-type")
113 .and_then(|v| v.to_str().ok())
114 .unwrap_or("application/octet-stream");
115 let content_type = super::ContentType::from(content_type);
116
117 if !status.is_client_error() && !status.is_server_error() {
118 let content = resp.text().await?;
119 match content_type {
120 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
121 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SemanticCacheStats`"))),
122 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SemanticCacheStats`")))),
123 }
124 } else {
125 let content = resp.text().await?;
126 let entity: Option<GetStatsError> = serde_json::from_str(&content).ok();
127 Err(Error::ResponseError(ResponseContent { status, content, entity }))
128 }
129}
130
131pub async fn invalidate_all(configuration: &configuration::Configuration, ) -> Result<models::InvalidateResponse, Error<InvalidateAllError>> {
132
133 let uri_str = format!("{}/v1/semantic-cache/invalidate", configuration.base_path);
134 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
135
136 if let Some(ref user_agent) = configuration.user_agent {
137 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
138 }
139 if let Some(ref token) = configuration.bearer_access_token {
140 req_builder = req_builder.bearer_auth(token.to_owned());
141 };
142
143 let req = req_builder.build()?;
144 let resp = configuration.client.execute(req).await?;
145
146 let status = resp.status();
147 let content_type = resp
148 .headers()
149 .get("content-type")
150 .and_then(|v| v.to_str().ok())
151 .unwrap_or("application/octet-stream");
152 let content_type = super::ContentType::from(content_type);
153
154 if !status.is_client_error() && !status.is_server_error() {
155 let content = resp.text().await?;
156 match content_type {
157 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
158 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::InvalidateResponse`"))),
159 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::InvalidateResponse`")))),
160 }
161 } else {
162 let content = resp.text().await?;
163 let entity: Option<InvalidateAllError> = serde_json::from_str(&content).ok();
164 Err(Error::ResponseError(ResponseContent { status, content, entity }))
165 }
166}
167
168pub async fn update_config(configuration: &configuration::Configuration, semantic_cache_config: models::SemanticCacheConfig) -> Result<(), Error<UpdateConfigError>> {
169 let p_semantic_cache_config = semantic_cache_config;
171
172 let uri_str = format!("{}/v1/semantic-cache/config", configuration.base_path);
173 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
174
175 if let Some(ref user_agent) = configuration.user_agent {
176 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
177 }
178 if let Some(ref token) = configuration.bearer_access_token {
179 req_builder = req_builder.bearer_auth(token.to_owned());
180 };
181 req_builder = req_builder.json(&p_semantic_cache_config);
182
183 let req = req_builder.build()?;
184 let resp = configuration.client.execute(req).await?;
185
186 let status = resp.status();
187
188 if !status.is_client_error() && !status.is_server_error() {
189 Ok(())
190 } else {
191 let content = resp.text().await?;
192 let entity: Option<UpdateConfigError> = serde_json::from_str(&content).ok();
193 Err(Error::ResponseError(ResponseContent { status, content, entity }))
194 }
195}
196