Skip to main content

mistral_openapi_client/apis/
batch_api.rs

1/*
2 * Mistral AI API
3 *
4 * Our Chat Completion and Embeddings APIs specification. Create your account on [La Plateforme](https://console.mistral.ai) to get access and read the [docs](https://docs.mistral.ai) to learn how to use it.
5 *
6 * The version of the OpenAPI document: 1.0.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`jobs_api_routes_batch_cancel_batch_job`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum JobsApiRoutesBatchCancelBatchJobError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`jobs_api_routes_batch_create_batch_job`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum JobsApiRoutesBatchCreateBatchJobError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`jobs_api_routes_batch_get_batch_job`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum JobsApiRoutesBatchGetBatchJobError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`jobs_api_routes_batch_get_batch_jobs`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum JobsApiRoutesBatchGetBatchJobsError {
43    UnknownValue(serde_json::Value),
44}
45
46
47/// Request the cancellation of a batch job.
48pub async fn jobs_api_routes_batch_cancel_batch_job(configuration: &configuration::Configuration, job_id: &str) -> Result<models::BatchJobOut, Error<JobsApiRoutesBatchCancelBatchJobError>> {
49    // add a prefix to parameters to efficiently prevent name collisions
50    let p_path_job_id = job_id;
51
52    let uri_str = format!("{}/v1/batch/jobs/{job_id}/cancel", configuration.base_path, job_id=crate::apis::urlencode(p_path_job_id));
53    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
54
55    if let Some(ref user_agent) = configuration.user_agent {
56        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
57    }
58    if let Some(ref token) = configuration.bearer_access_token {
59        req_builder = req_builder.bearer_auth(token.to_owned());
60    };
61
62    let req = req_builder.build()?;
63    let resp = configuration.client.execute(req).await?;
64
65    let status = resp.status();
66    let content_type = resp
67        .headers()
68        .get("content-type")
69        .and_then(|v| v.to_str().ok())
70        .unwrap_or("application/octet-stream");
71    let content_type = super::ContentType::from(content_type);
72
73    if !status.is_client_error() && !status.is_server_error() {
74        let content = resp.text().await?;
75        match content_type {
76            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
77            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BatchJobOut`"))),
78            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::BatchJobOut`")))),
79        }
80    } else {
81        let content = resp.text().await?;
82        let entity: Option<JobsApiRoutesBatchCancelBatchJobError> = serde_json::from_str(&content).ok();
83        Err(Error::ResponseError(ResponseContent { status, content, entity }))
84    }
85}
86
87/// Create a new batch job, it will be queued for processing.
88pub async fn jobs_api_routes_batch_create_batch_job(configuration: &configuration::Configuration, batch_job_in: models::BatchJobIn) -> Result<models::BatchJobOut, Error<JobsApiRoutesBatchCreateBatchJobError>> {
89    // add a prefix to parameters to efficiently prevent name collisions
90    let p_body_batch_job_in = batch_job_in;
91
92    let uri_str = format!("{}/v1/batch/jobs", configuration.base_path);
93    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
94
95    if let Some(ref user_agent) = configuration.user_agent {
96        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
97    }
98    if let Some(ref token) = configuration.bearer_access_token {
99        req_builder = req_builder.bearer_auth(token.to_owned());
100    };
101    req_builder = req_builder.json(&p_body_batch_job_in);
102
103    let req = req_builder.build()?;
104    let resp = configuration.client.execute(req).await?;
105
106    let status = resp.status();
107    let content_type = resp
108        .headers()
109        .get("content-type")
110        .and_then(|v| v.to_str().ok())
111        .unwrap_or("application/octet-stream");
112    let content_type = super::ContentType::from(content_type);
113
114    if !status.is_client_error() && !status.is_server_error() {
115        let content = resp.text().await?;
116        match content_type {
117            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
118            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BatchJobOut`"))),
119            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::BatchJobOut`")))),
120        }
121    } else {
122        let content = resp.text().await?;
123        let entity: Option<JobsApiRoutesBatchCreateBatchJobError> = serde_json::from_str(&content).ok();
124        Err(Error::ResponseError(ResponseContent { status, content, entity }))
125    }
126}
127
128/// Get a batch job details by its UUID.  Args:     inline: If True, return results inline in the response.
129pub async fn jobs_api_routes_batch_get_batch_job(configuration: &configuration::Configuration, job_id: &str, inline: Option<bool>) -> Result<models::BatchJobOut, Error<JobsApiRoutesBatchGetBatchJobError>> {
130    // add a prefix to parameters to efficiently prevent name collisions
131    let p_path_job_id = job_id;
132    let p_query_inline = inline;
133
134    let uri_str = format!("{}/v1/batch/jobs/{job_id}", configuration.base_path, job_id=crate::apis::urlencode(p_path_job_id));
135    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
136
137    if let Some(ref param_value) = p_query_inline {
138        req_builder = req_builder.query(&[("inline", &param_value.to_string())]);
139    }
140    if let Some(ref user_agent) = configuration.user_agent {
141        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
142    }
143    if let Some(ref token) = configuration.bearer_access_token {
144        req_builder = req_builder.bearer_auth(token.to_owned());
145    };
146
147    let req = req_builder.build()?;
148    let resp = configuration.client.execute(req).await?;
149
150    let status = resp.status();
151    let content_type = resp
152        .headers()
153        .get("content-type")
154        .and_then(|v| v.to_str().ok())
155        .unwrap_or("application/octet-stream");
156    let content_type = super::ContentType::from(content_type);
157
158    if !status.is_client_error() && !status.is_server_error() {
159        let content = resp.text().await?;
160        match content_type {
161            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
162            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BatchJobOut`"))),
163            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::BatchJobOut`")))),
164        }
165    } else {
166        let content = resp.text().await?;
167        let entity: Option<JobsApiRoutesBatchGetBatchJobError> = serde_json::from_str(&content).ok();
168        Err(Error::ResponseError(ResponseContent { status, content, entity }))
169    }
170}
171
172/// Get a list of batch jobs for your organization and user.
173pub async fn jobs_api_routes_batch_get_batch_jobs(configuration: &configuration::Configuration, page: Option<i32>, page_size: Option<i32>, model: Option<&str>, agent_id: Option<&str>, metadata: Option<std::collections::HashMap<String, serde_json::Value>>, created_after: Option<String>, created_by_me: Option<bool>, status: Option<Vec<models::BatchJobStatus>>, order_by: Option<&str>) -> Result<models::BatchJobsOut, Error<JobsApiRoutesBatchGetBatchJobsError>> {
174    // add a prefix to parameters to efficiently prevent name collisions
175    let p_query_page = page;
176    let p_query_page_size = page_size;
177    let p_query_model = model;
178    let p_query_agent_id = agent_id;
179    let p_query_metadata = metadata;
180    let p_query_created_after = created_after;
181    let p_query_created_by_me = created_by_me;
182    let p_query_status = status;
183    let p_query_order_by = order_by;
184
185    let uri_str = format!("{}/v1/batch/jobs", configuration.base_path);
186    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
187
188    if let Some(ref param_value) = p_query_page {
189        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
190    }
191    if let Some(ref param_value) = p_query_page_size {
192        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
193    }
194    if let Some(ref param_value) = p_query_model {
195        req_builder = req_builder.query(&[("model", &param_value.to_string())]);
196    }
197    if let Some(ref param_value) = p_query_agent_id {
198        req_builder = req_builder.query(&[("agent_id", &param_value.to_string())]);
199    }
200    if let Some(ref param_value) = p_query_metadata {
201        req_builder = req_builder.query(&[("metadata", &serde_json::to_string(param_value)?)]);
202    }
203    if let Some(ref param_value) = p_query_created_after {
204        req_builder = req_builder.query(&[("created_after", &param_value.to_string())]);
205    }
206    if let Some(ref param_value) = p_query_created_by_me {
207        req_builder = req_builder.query(&[("created_by_me", &param_value.to_string())]);
208    }
209    if let Some(ref param_value) = p_query_status {
210        req_builder = match "multi" {
211            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("status".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
212            _ => req_builder.query(&[("status", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
213        };
214    }
215    if let Some(ref param_value) = p_query_order_by {
216        req_builder = req_builder.query(&[("order_by", &param_value.to_string())]);
217    }
218    if let Some(ref user_agent) = configuration.user_agent {
219        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
220    }
221    if let Some(ref token) = configuration.bearer_access_token {
222        req_builder = req_builder.bearer_auth(token.to_owned());
223    };
224
225    let req = req_builder.build()?;
226    let resp = configuration.client.execute(req).await?;
227
228    let status = resp.status();
229    let content_type = resp
230        .headers()
231        .get("content-type")
232        .and_then(|v| v.to_str().ok())
233        .unwrap_or("application/octet-stream");
234    let content_type = super::ContentType::from(content_type);
235
236    if !status.is_client_error() && !status.is_server_error() {
237        let content = resp.text().await?;
238        match content_type {
239            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
240            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BatchJobsOut`"))),
241            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::BatchJobsOut`")))),
242        }
243    } else {
244        let content = resp.text().await?;
245        let entity: Option<JobsApiRoutesBatchGetBatchJobsError> = serde_json::from_str(&content).ok();
246        Err(Error::ResponseError(ResponseContent { status, content, entity }))
247    }
248}
249