1use 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 CreateModelError {
22 Status401(models::ApiError),
23 Status403(models::ApiError),
24 UnknownValue(serde_json::Value),
25}
26
27#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum DeleteModelError {
31 Status401(models::ApiError),
32 UnknownValue(serde_json::Value),
33}
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum GetActiveModelError {
39 Status401(models::ApiError),
40 UnknownValue(serde_json::Value),
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize)]
45#[serde(untagged)]
46pub enum GetModelError {
47 Status401(models::ApiError),
48 UnknownValue(serde_json::Value),
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize)]
53#[serde(untagged)]
54pub enum ListModelsError {
55 Status401(models::ApiError),
56 UnknownValue(serde_json::Value),
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum SetActiveModelError {
63 Status401(models::ApiError),
64 UnknownValue(serde_json::Value),
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize)]
69#[serde(untagged)]
70pub enum UpdateModelError {
71 Status401(models::ApiError),
72 Status403(models::ApiError),
73 UnknownValue(serde_json::Value),
74}
75
76
77pub async fn create_model(configuration: &configuration::Configuration, request_body: std::collections::HashMap<String, serde_json::Value>) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<CreateModelError>> {
78 let p_body_request_body = request_body;
80
81 let uri_str = format!("{}/v1/models", configuration.base_path);
82 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
83
84 if let Some(ref user_agent) = configuration.user_agent {
85 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
86 }
87 if let Some(ref token) = configuration.bearer_access_token {
88 req_builder = req_builder.bearer_auth(token.to_owned());
89 };
90 req_builder = req_builder.json(&p_body_request_body);
91
92 let req = req_builder.build()?;
93 let resp = configuration.client.execute(req).await?;
94
95 let status = resp.status();
96 let content_type = resp
97 .headers()
98 .get("content-type")
99 .and_then(|v| v.to_str().ok())
100 .unwrap_or("application/octet-stream");
101 let content_type = super::ContentType::from(content_type);
102
103 if !status.is_client_error() && !status.is_server_error() {
104 let content = resp.text().await?;
105 match content_type {
106 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
107 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`"))),
108 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`")))),
109 }
110 } else {
111 let content = resp.text().await?;
112 let entity: Option<CreateModelError> = serde_json::from_str(&content).ok();
113 Err(Error::ResponseError(ResponseContent { status, content, entity }))
114 }
115}
116
117pub async fn delete_model(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteModelError>> {
118 let p_path_id = id;
120
121 let uri_str = format!("{}/v1/models/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
122 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
123
124 if let Some(ref user_agent) = configuration.user_agent {
125 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
126 }
127 if let Some(ref token) = configuration.bearer_access_token {
128 req_builder = req_builder.bearer_auth(token.to_owned());
129 };
130
131 let req = req_builder.build()?;
132 let resp = configuration.client.execute(req).await?;
133
134 let status = resp.status();
135
136 if !status.is_client_error() && !status.is_server_error() {
137 Ok(())
138 } else {
139 let content = resp.text().await?;
140 let entity: Option<DeleteModelError> = serde_json::from_str(&content).ok();
141 Err(Error::ResponseError(ResponseContent { status, content, entity }))
142 }
143}
144
145pub async fn get_active_model(configuration: &configuration::Configuration, provider: Option<&str>) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<GetActiveModelError>> {
146 let p_query_provider = provider;
148
149 let uri_str = format!("{}/v1/models/active", configuration.base_path);
150 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
151
152 if let Some(ref param_value) = p_query_provider {
153 req_builder = req_builder.query(&[("provider", ¶m_value.to_string())]);
154 }
155 if let Some(ref user_agent) = configuration.user_agent {
156 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
157 }
158 if let Some(ref token) = configuration.bearer_access_token {
159 req_builder = req_builder.bearer_auth(token.to_owned());
160 };
161
162 let req = req_builder.build()?;
163 let resp = configuration.client.execute(req).await?;
164
165 let status = resp.status();
166 let content_type = resp
167 .headers()
168 .get("content-type")
169 .and_then(|v| v.to_str().ok())
170 .unwrap_or("application/octet-stream");
171 let content_type = super::ContentType::from(content_type);
172
173 if !status.is_client_error() && !status.is_server_error() {
174 let content = resp.text().await?;
175 match content_type {
176 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
177 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`"))),
178 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`")))),
179 }
180 } else {
181 let content = resp.text().await?;
182 let entity: Option<GetActiveModelError> = serde_json::from_str(&content).ok();
183 Err(Error::ResponseError(ResponseContent { status, content, entity }))
184 }
185}
186
187pub async fn get_model(configuration: &configuration::Configuration, id: &str) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<GetModelError>> {
188 let p_path_id = id;
190
191 let uri_str = format!("{}/v1/models/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
192 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
193
194 if let Some(ref user_agent) = configuration.user_agent {
195 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
196 }
197 if let Some(ref token) = configuration.bearer_access_token {
198 req_builder = req_builder.bearer_auth(token.to_owned());
199 };
200
201 let req = req_builder.build()?;
202 let resp = configuration.client.execute(req).await?;
203
204 let status = resp.status();
205 let content_type = resp
206 .headers()
207 .get("content-type")
208 .and_then(|v| v.to_str().ok())
209 .unwrap_or("application/octet-stream");
210 let content_type = super::ContentType::from(content_type);
211
212 if !status.is_client_error() && !status.is_server_error() {
213 let content = resp.text().await?;
214 match content_type {
215 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
216 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`"))),
217 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`")))),
218 }
219 } else {
220 let content = resp.text().await?;
221 let entity: Option<GetModelError> = serde_json::from_str(&content).ok();
222 Err(Error::ResponseError(ResponseContent { status, content, entity }))
223 }
224}
225
226pub async fn list_models(configuration: &configuration::Configuration, ) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<ListModelsError>> {
227
228 let uri_str = format!("{}/v1/models", configuration.base_path);
229 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
230
231 if let Some(ref user_agent) = configuration.user_agent {
232 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
233 }
234 if let Some(ref token) = configuration.bearer_access_token {
235 req_builder = req_builder.bearer_auth(token.to_owned());
236 };
237
238 let req = req_builder.build()?;
239 let resp = configuration.client.execute(req).await?;
240
241 let status = resp.status();
242 let content_type = resp
243 .headers()
244 .get("content-type")
245 .and_then(|v| v.to_str().ok())
246 .unwrap_or("application/octet-stream");
247 let content_type = super::ContentType::from(content_type);
248
249 if !status.is_client_error() && !status.is_server_error() {
250 let content = resp.text().await?;
251 match content_type {
252 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
253 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`"))),
254 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`")))),
255 }
256 } else {
257 let content = resp.text().await?;
258 let entity: Option<ListModelsError> = serde_json::from_str(&content).ok();
259 Err(Error::ResponseError(ResponseContent { status, content, entity }))
260 }
261}
262
263pub async fn set_active_model(configuration: &configuration::Configuration, id: &str) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<SetActiveModelError>> {
264 let p_path_id = id;
266
267 let uri_str = format!("{}/v1/models/{id}/activate", configuration.base_path, id=crate::apis::urlencode(p_path_id));
268 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
269
270 if let Some(ref user_agent) = configuration.user_agent {
271 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
272 }
273 if let Some(ref token) = configuration.bearer_access_token {
274 req_builder = req_builder.bearer_auth(token.to_owned());
275 };
276
277 let req = req_builder.build()?;
278 let resp = configuration.client.execute(req).await?;
279
280 let status = resp.status();
281 let content_type = resp
282 .headers()
283 .get("content-type")
284 .and_then(|v| v.to_str().ok())
285 .unwrap_or("application/octet-stream");
286 let content_type = super::ContentType::from(content_type);
287
288 if !status.is_client_error() && !status.is_server_error() {
289 let content = resp.text().await?;
290 match content_type {
291 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
292 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`"))),
293 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`")))),
294 }
295 } else {
296 let content = resp.text().await?;
297 let entity: Option<SetActiveModelError> = serde_json::from_str(&content).ok();
298 Err(Error::ResponseError(ResponseContent { status, content, entity }))
299 }
300}
301
302pub async fn update_model(configuration: &configuration::Configuration, id: &str, request_body: std::collections::HashMap<String, serde_json::Value>) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<UpdateModelError>> {
303 let p_path_id = id;
305 let p_body_request_body = request_body;
306
307 let uri_str = format!("{}/v1/models/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id));
308 let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
309
310 if let Some(ref user_agent) = configuration.user_agent {
311 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
312 }
313 if let Some(ref token) = configuration.bearer_access_token {
314 req_builder = req_builder.bearer_auth(token.to_owned());
315 };
316 req_builder = req_builder.json(&p_body_request_body);
317
318 let req = req_builder.build()?;
319 let resp = configuration.client.execute(req).await?;
320
321 let status = resp.status();
322 let content_type = resp
323 .headers()
324 .get("content-type")
325 .and_then(|v| v.to_str().ok())
326 .unwrap_or("application/octet-stream");
327 let content_type = super::ContentType::from(content_type);
328
329 if !status.is_client_error() && !status.is_server_error() {
330 let content = resp.text().await?;
331 match content_type {
332 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
333 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`"))),
334 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`")))),
335 }
336 } else {
337 let content = resp.text().await?;
338 let entity: Option<UpdateModelError> = serde_json::from_str(&content).ok();
339 Err(Error::ResponseError(ResponseContent { status, content, entity }))
340 }
341}
342