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 ModelsCreateError {
22 Status400(serde_json::Value),
23 Status401(serde_json::Value),
24 Status403(serde_json::Value),
25 Status404(serde_json::Value),
26 Status405(serde_json::Value),
27 UnknownValue(serde_json::Value),
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum ModelsDeleteError {
34 Status400(serde_json::Value),
35 Status401(serde_json::Value),
36 Status403(serde_json::Value),
37 Status404(serde_json::Value),
38 Status405(serde_json::Value),
39 UnknownValue(serde_json::Value),
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum ModelsGetError {
46 Status400(serde_json::Value),
47 Status401(serde_json::Value),
48 Status403(serde_json::Value),
49 Status404(serde_json::Value),
50 Status405(serde_json::Value),
51 UnknownValue(serde_json::Value),
52}
53
54#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(untagged)]
57pub enum ModelsListError {
58 Status400(serde_json::Value),
59 Status401(serde_json::Value),
60 Status403(serde_json::Value),
61 Status404(serde_json::Value),
62 Status405(serde_json::Value),
63 UnknownValue(serde_json::Value),
64}
65
66
67pub async fn models_create(configuration: &configuration::Configuration, create_model_request: models::CreateModelRequest) -> Result<models::Model, Error<ModelsCreateError>> {
69 let p_create_model_request = create_model_request;
71
72 let uri_str = format!("{}/api/public/models", configuration.base_path);
73 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
74
75 if let Some(ref user_agent) = configuration.user_agent {
76 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
77 }
78 if let Some(ref auth_conf) = configuration.basic_auth {
79 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
80 };
81 req_builder = req_builder.json(&p_create_model_request);
82
83 let req = req_builder.build()?;
84 let resp = configuration.client.execute(req).await?;
85
86 let status = resp.status();
87 let content_type = resp
88 .headers()
89 .get("content-type")
90 .and_then(|v| v.to_str().ok())
91 .unwrap_or("application/octet-stream");
92 let content_type = super::ContentType::from(content_type);
93
94 if !status.is_client_error() && !status.is_server_error() {
95 let content = resp.text().await?;
96 match content_type {
97 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
98 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Model`"))),
99 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::Model`")))),
100 }
101 } else {
102 let content = resp.text().await?;
103 let entity: Option<ModelsCreateError> = serde_json::from_str(&content).ok();
104 Err(Error::ResponseError(ResponseContent { status, content, entity }))
105 }
106}
107
108pub async fn models_delete(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<ModelsDeleteError>> {
110 let p_id = id;
112
113 let uri_str = format!("{}/api/public/models/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
114 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
115
116 if let Some(ref user_agent) = configuration.user_agent {
117 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
118 }
119 if let Some(ref auth_conf) = configuration.basic_auth {
120 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
121 };
122
123 let req = req_builder.build()?;
124 let resp = configuration.client.execute(req).await?;
125
126 let status = resp.status();
127
128 if !status.is_client_error() && !status.is_server_error() {
129 Ok(())
130 } else {
131 let content = resp.text().await?;
132 let entity: Option<ModelsDeleteError> = serde_json::from_str(&content).ok();
133 Err(Error::ResponseError(ResponseContent { status, content, entity }))
134 }
135}
136
137pub async fn models_get(configuration: &configuration::Configuration, id: &str) -> Result<models::Model, Error<ModelsGetError>> {
139 let p_id = id;
141
142 let uri_str = format!("{}/api/public/models/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
143 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
144
145 if let Some(ref user_agent) = configuration.user_agent {
146 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
147 }
148 if let Some(ref auth_conf) = configuration.basic_auth {
149 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
150 };
151
152 let req = req_builder.build()?;
153 let resp = configuration.client.execute(req).await?;
154
155 let status = resp.status();
156 let content_type = resp
157 .headers()
158 .get("content-type")
159 .and_then(|v| v.to_str().ok())
160 .unwrap_or("application/octet-stream");
161 let content_type = super::ContentType::from(content_type);
162
163 if !status.is_client_error() && !status.is_server_error() {
164 let content = resp.text().await?;
165 match content_type {
166 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
167 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Model`"))),
168 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::Model`")))),
169 }
170 } else {
171 let content = resp.text().await?;
172 let entity: Option<ModelsGetError> = serde_json::from_str(&content).ok();
173 Err(Error::ResponseError(ResponseContent { status, content, entity }))
174 }
175}
176
177pub async fn models_list(configuration: &configuration::Configuration, page: Option<i32>, limit: Option<i32>) -> Result<models::PaginatedModels, Error<ModelsListError>> {
179 let p_page = page;
181 let p_limit = limit;
182
183 let uri_str = format!("{}/api/public/models", configuration.base_path);
184 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
185
186 if let Some(ref param_value) = p_page {
187 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
188 }
189 if let Some(ref param_value) = p_limit {
190 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
191 }
192 if let Some(ref user_agent) = configuration.user_agent {
193 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
194 }
195 if let Some(ref auth_conf) = configuration.basic_auth {
196 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
197 };
198
199 let req = req_builder.build()?;
200 let resp = configuration.client.execute(req).await?;
201
202 let status = resp.status();
203 let content_type = resp
204 .headers()
205 .get("content-type")
206 .and_then(|v| v.to_str().ok())
207 .unwrap_or("application/octet-stream");
208 let content_type = super::ContentType::from(content_type);
209
210 if !status.is_client_error() && !status.is_server_error() {
211 let content = resp.text().await?;
212 match content_type {
213 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
214 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PaginatedModels`"))),
215 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::PaginatedModels`")))),
216 }
217 } else {
218 let content = resp.text().await?;
219 let entity: Option<ModelsListError> = serde_json::from_str(&content).ok();
220 Err(Error::ResponseError(ResponseContent { status, content, entity }))
221 }
222}
223