Skip to main content

mistral_openapi_client/apis/
models_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 [`delete_model_v1_models_model_id_delete`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DeleteModelV1ModelsModelIdDeleteError {
22    Status422(models::HttpValidationError),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`jobs_api_routes_fine_tuning_archive_fine_tuned_model`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum JobsApiRoutesFineTuningArchiveFineTunedModelError {
30    UnknownValue(serde_json::Value),
31}
32
33/// struct for typed errors of method [`jobs_api_routes_fine_tuning_unarchive_fine_tuned_model`]
34#[derive(Debug, Clone, Serialize, Deserialize)]
35#[serde(untagged)]
36pub enum JobsApiRoutesFineTuningUnarchiveFineTunedModelError {
37    UnknownValue(serde_json::Value),
38}
39
40/// struct for typed errors of method [`jobs_api_routes_fine_tuning_update_fine_tuned_model`]
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum JobsApiRoutesFineTuningUpdateFineTunedModelError {
44    UnknownValue(serde_json::Value),
45}
46
47/// struct for typed errors of method [`list_models_v1_models_get`]
48#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(untagged)]
50pub enum ListModelsV1ModelsGetError {
51    Status422(models::HttpValidationError),
52    UnknownValue(serde_json::Value),
53}
54
55/// struct for typed errors of method [`retrieve_model_v1_models_model_id_get`]
56#[derive(Debug, Clone, Serialize, Deserialize)]
57#[serde(untagged)]
58pub enum RetrieveModelV1ModelsModelIdGetError {
59    Status422(models::HttpValidationError),
60    UnknownValue(serde_json::Value),
61}
62
63
64/// Delete a fine-tuned model.
65pub async fn delete_model_v1_models_model_id_delete(configuration: &configuration::Configuration, model_id: &str) -> Result<models::DeleteModelOut, Error<DeleteModelV1ModelsModelIdDeleteError>> {
66    // add a prefix to parameters to efficiently prevent name collisions
67    let p_path_model_id = model_id;
68
69    let uri_str = format!("{}/v1/models/{model_id}", configuration.base_path, model_id=crate::apis::urlencode(p_path_model_id));
70    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
71
72    if let Some(ref user_agent) = configuration.user_agent {
73        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
74    }
75    if let Some(ref token) = configuration.bearer_access_token {
76        req_builder = req_builder.bearer_auth(token.to_owned());
77    };
78
79    let req = req_builder.build()?;
80    let resp = configuration.client.execute(req).await?;
81
82    let status = resp.status();
83    let content_type = resp
84        .headers()
85        .get("content-type")
86        .and_then(|v| v.to_str().ok())
87        .unwrap_or("application/octet-stream");
88    let content_type = super::ContentType::from(content_type);
89
90    if !status.is_client_error() && !status.is_server_error() {
91        let content = resp.text().await?;
92        match content_type {
93            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
94            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteModelOut`"))),
95            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::DeleteModelOut`")))),
96        }
97    } else {
98        let content = resp.text().await?;
99        let entity: Option<DeleteModelV1ModelsModelIdDeleteError> = serde_json::from_str(&content).ok();
100        Err(Error::ResponseError(ResponseContent { status, content, entity }))
101    }
102}
103
104/// Archive a fine-tuned model.
105pub async fn jobs_api_routes_fine_tuning_archive_fine_tuned_model(configuration: &configuration::Configuration, model_id: &str) -> Result<models::ArchiveFtModelOut, Error<JobsApiRoutesFineTuningArchiveFineTunedModelError>> {
106    // add a prefix to parameters to efficiently prevent name collisions
107    let p_path_model_id = model_id;
108
109    let uri_str = format!("{}/v1/fine_tuning/models/{model_id}/archive", configuration.base_path, model_id=crate::apis::urlencode(p_path_model_id));
110    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
111
112    if let Some(ref user_agent) = configuration.user_agent {
113        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
114    }
115    if let Some(ref token) = configuration.bearer_access_token {
116        req_builder = req_builder.bearer_auth(token.to_owned());
117    };
118
119    let req = req_builder.build()?;
120    let resp = configuration.client.execute(req).await?;
121
122    let status = resp.status();
123    let content_type = resp
124        .headers()
125        .get("content-type")
126        .and_then(|v| v.to_str().ok())
127        .unwrap_or("application/octet-stream");
128    let content_type = super::ContentType::from(content_type);
129
130    if !status.is_client_error() && !status.is_server_error() {
131        let content = resp.text().await?;
132        match content_type {
133            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
134            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ArchiveFtModelOut`"))),
135            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::ArchiveFtModelOut`")))),
136        }
137    } else {
138        let content = resp.text().await?;
139        let entity: Option<JobsApiRoutesFineTuningArchiveFineTunedModelError> = serde_json::from_str(&content).ok();
140        Err(Error::ResponseError(ResponseContent { status, content, entity }))
141    }
142}
143
144/// Un-archive a fine-tuned model.
145pub async fn jobs_api_routes_fine_tuning_unarchive_fine_tuned_model(configuration: &configuration::Configuration, model_id: &str) -> Result<models::UnarchiveFtModelOut, Error<JobsApiRoutesFineTuningUnarchiveFineTunedModelError>> {
146    // add a prefix to parameters to efficiently prevent name collisions
147    let p_path_model_id = model_id;
148
149    let uri_str = format!("{}/v1/fine_tuning/models/{model_id}/archive", configuration.base_path, model_id=crate::apis::urlencode(p_path_model_id));
150    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
151
152    if let Some(ref user_agent) = configuration.user_agent {
153        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
154    }
155    if let Some(ref token) = configuration.bearer_access_token {
156        req_builder = req_builder.bearer_auth(token.to_owned());
157    };
158
159    let req = req_builder.build()?;
160    let resp = configuration.client.execute(req).await?;
161
162    let status = resp.status();
163    let content_type = resp
164        .headers()
165        .get("content-type")
166        .and_then(|v| v.to_str().ok())
167        .unwrap_or("application/octet-stream");
168    let content_type = super::ContentType::from(content_type);
169
170    if !status.is_client_error() && !status.is_server_error() {
171        let content = resp.text().await?;
172        match content_type {
173            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
174            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UnarchiveFtModelOut`"))),
175            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::UnarchiveFtModelOut`")))),
176        }
177    } else {
178        let content = resp.text().await?;
179        let entity: Option<JobsApiRoutesFineTuningUnarchiveFineTunedModelError> = serde_json::from_str(&content).ok();
180        Err(Error::ResponseError(ResponseContent { status, content, entity }))
181    }
182}
183
184/// Update a model name or description.
185pub async fn jobs_api_routes_fine_tuning_update_fine_tuned_model(configuration: &configuration::Configuration, model_id: &str, update_ft_model_in: models::UpdateFtModelIn) -> Result<models::Response2, Error<JobsApiRoutesFineTuningUpdateFineTunedModelError>> {
186    // add a prefix to parameters to efficiently prevent name collisions
187    let p_path_model_id = model_id;
188    let p_body_update_ft_model_in = update_ft_model_in;
189
190    let uri_str = format!("{}/v1/fine_tuning/models/{model_id}", configuration.base_path, model_id=crate::apis::urlencode(p_path_model_id));
191    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
192
193    if let Some(ref user_agent) = configuration.user_agent {
194        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
195    }
196    if let Some(ref token) = configuration.bearer_access_token {
197        req_builder = req_builder.bearer_auth(token.to_owned());
198    };
199    req_builder = req_builder.json(&p_body_update_ft_model_in);
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 `models::Response2`"))),
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 `models::Response2`")))),
218        }
219    } else {
220        let content = resp.text().await?;
221        let entity: Option<JobsApiRoutesFineTuningUpdateFineTunedModelError> = serde_json::from_str(&content).ok();
222        Err(Error::ResponseError(ResponseContent { status, content, entity }))
223    }
224}
225
226/// List all models available to the user.
227pub async fn list_models_v1_models_get(configuration: &configuration::Configuration, provider: Option<&str>, model: Option<&str>) -> Result<models::ModelList, Error<ListModelsV1ModelsGetError>> {
228    // add a prefix to parameters to efficiently prevent name collisions
229    let p_query_provider = provider;
230    let p_query_model = model;
231
232    let uri_str = format!("{}/v1/models", configuration.base_path);
233    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
234
235    if let Some(ref param_value) = p_query_provider {
236        req_builder = req_builder.query(&[("provider", &param_value.to_string())]);
237    }
238    if let Some(ref param_value) = p_query_model {
239        req_builder = req_builder.query(&[("model", &param_value.to_string())]);
240    }
241    if let Some(ref user_agent) = configuration.user_agent {
242        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
243    }
244    if let Some(ref token) = configuration.bearer_access_token {
245        req_builder = req_builder.bearer_auth(token.to_owned());
246    };
247
248    let req = req_builder.build()?;
249    let resp = configuration.client.execute(req).await?;
250
251    let status = resp.status();
252    let content_type = resp
253        .headers()
254        .get("content-type")
255        .and_then(|v| v.to_str().ok())
256        .unwrap_or("application/octet-stream");
257    let content_type = super::ContentType::from(content_type);
258
259    if !status.is_client_error() && !status.is_server_error() {
260        let content = resp.text().await?;
261        match content_type {
262            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
263            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ModelList`"))),
264            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::ModelList`")))),
265        }
266    } else {
267        let content = resp.text().await?;
268        let entity: Option<ListModelsV1ModelsGetError> = serde_json::from_str(&content).ok();
269        Err(Error::ResponseError(ResponseContent { status, content, entity }))
270    }
271}
272
273/// Retrieve information about a model.
274pub async fn retrieve_model_v1_models_model_id_get(configuration: &configuration::Configuration, model_id: &str) -> Result<models::ResponseRetrieveModelV1ModelsModelIdGet, Error<RetrieveModelV1ModelsModelIdGetError>> {
275    // add a prefix to parameters to efficiently prevent name collisions
276    let p_path_model_id = model_id;
277
278    let uri_str = format!("{}/v1/models/{model_id}", configuration.base_path, model_id=crate::apis::urlencode(p_path_model_id));
279    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
280
281    if let Some(ref user_agent) = configuration.user_agent {
282        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
283    }
284    if let Some(ref token) = configuration.bearer_access_token {
285        req_builder = req_builder.bearer_auth(token.to_owned());
286    };
287
288    let req = req_builder.build()?;
289    let resp = configuration.client.execute(req).await?;
290
291    let status = resp.status();
292    let content_type = resp
293        .headers()
294        .get("content-type")
295        .and_then(|v| v.to_str().ok())
296        .unwrap_or("application/octet-stream");
297    let content_type = super::ContentType::from(content_type);
298
299    if !status.is_client_error() && !status.is_server_error() {
300        let content = resp.text().await?;
301        match content_type {
302            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
303            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ResponseRetrieveModelV1ModelsModelIdGet`"))),
304            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::ResponseRetrieveModelV1ModelsModelIdGet`")))),
305        }
306    } else {
307        let content = resp.text().await?;
308        let entity: Option<RetrieveModelV1ModelsModelIdGetError> = serde_json::from_str(&content).ok();
309        Err(Error::ResponseError(ResponseContent { status, content, entity }))
310    }
311}
312