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