geoengine_api_client/apis/
ml_api.rs1use reqwest;
12use serde::{Deserialize, Serialize, de::Error as _};
13use crate::{apis::ResponseContent, models};
14use super::{Error, configuration, ContentType};
15
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum AddMlModelError {
21 UnknownValue(serde_json::Value),
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum GetMlModelError {
28 UnknownValue(serde_json::Value),
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum ListMlModelsError {
35 UnknownValue(serde_json::Value),
36}
37
38
39pub async fn add_ml_model(configuration: &configuration::Configuration, ml_model: models::MlModel) -> Result<models::MlModelNameResponse, Error<AddMlModelError>> {
40 let p_body_ml_model = ml_model;
42
43 let uri_str = format!("{}/ml/models", configuration.base_path);
44 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
45
46 if let Some(ref user_agent) = configuration.user_agent {
47 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
48 }
49 if let Some(ref token) = configuration.bearer_access_token {
50 req_builder = req_builder.bearer_auth(token.to_owned());
51 };
52 req_builder = req_builder.json(&p_body_ml_model);
53
54 let req = req_builder.build()?;
55 let resp = configuration.client.execute(req).await?;
56
57 let status = resp.status();
58 let content_type = resp
59 .headers()
60 .get("content-type")
61 .and_then(|v| v.to_str().ok())
62 .unwrap_or("application/octet-stream");
63 let content_type = super::ContentType::from(content_type);
64
65 if !status.is_client_error() && !status.is_server_error() {
66 let content = resp.text().await?;
67 match content_type {
68 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
69 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MlModelNameResponse`"))),
70 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::MlModelNameResponse`")))),
71 }
72 } else {
73 let content = resp.text().await?;
74 let entity: Option<AddMlModelError> = serde_json::from_str(&content).ok();
75 Err(Error::ResponseError(ResponseContent { status, content, entity }))
76 }
77}
78
79pub async fn get_ml_model(configuration: &configuration::Configuration, model_name: &str) -> Result<models::MlModel, Error<GetMlModelError>> {
80 let p_path_model_name = model_name;
82
83 let uri_str = format!("{}/ml/models/{model_name}", configuration.base_path, model_name=crate::apis::urlencode(p_path_model_name));
84 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
85
86 if let Some(ref user_agent) = configuration.user_agent {
87 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
88 }
89 if let Some(ref token) = configuration.bearer_access_token {
90 req_builder = req_builder.bearer_auth(token.to_owned());
91 };
92
93 let req = req_builder.build()?;
94 let resp = configuration.client.execute(req).await?;
95
96 let status = resp.status();
97 let content_type = resp
98 .headers()
99 .get("content-type")
100 .and_then(|v| v.to_str().ok())
101 .unwrap_or("application/octet-stream");
102 let content_type = super::ContentType::from(content_type);
103
104 if !status.is_client_error() && !status.is_server_error() {
105 let content = resp.text().await?;
106 match content_type {
107 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
108 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MlModel`"))),
109 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::MlModel`")))),
110 }
111 } else {
112 let content = resp.text().await?;
113 let entity: Option<GetMlModelError> = serde_json::from_str(&content).ok();
114 Err(Error::ResponseError(ResponseContent { status, content, entity }))
115 }
116}
117
118pub async fn list_ml_models(configuration: &configuration::Configuration, ) -> Result<Vec<models::MlModel>, Error<ListMlModelsError>> {
119
120 let uri_str = format!("{}/ml/models", configuration.base_path);
121 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
122
123 if let Some(ref user_agent) = configuration.user_agent {
124 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
125 }
126 if let Some(ref token) = configuration.bearer_access_token {
127 req_builder = req_builder.bearer_auth(token.to_owned());
128 };
129
130 let req = req_builder.build()?;
131 let resp = configuration.client.execute(req).await?;
132
133 let status = resp.status();
134 let content_type = resp
135 .headers()
136 .get("content-type")
137 .and_then(|v| v.to_str().ok())
138 .unwrap_or("application/octet-stream");
139 let content_type = super::ContentType::from(content_type);
140
141 if !status.is_client_error() && !status.is_server_error() {
142 let content = resp.text().await?;
143 match content_type {
144 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
145 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::MlModel>`"))),
146 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::MlModel>`")))),
147 }
148 } else {
149 let content = resp.text().await?;
150 let entity: Option<ListMlModelsError> = serde_json::from_str(&content).ok();
151 Err(Error::ResponseError(ResponseContent { status, content, entity }))
152 }
153}
154