mistral-openapi-client 0.1.0

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.
Documentation
/*
 * Mistral AI API
 *
 * 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.
 *
 * The version of the OpenAPI document: 1.0.0
 * 
 * Generated by: https://openapi-generator.tech
 */


use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};


/// struct for typed errors of method [`jobs_api_routes_batch_cancel_batch_job`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum JobsApiRoutesBatchCancelBatchJobError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`jobs_api_routes_batch_create_batch_job`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum JobsApiRoutesBatchCreateBatchJobError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`jobs_api_routes_batch_get_batch_job`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum JobsApiRoutesBatchGetBatchJobError {
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`jobs_api_routes_batch_get_batch_jobs`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum JobsApiRoutesBatchGetBatchJobsError {
    UnknownValue(serde_json::Value),
}


/// Request the cancellation of a batch job.
pub async fn jobs_api_routes_batch_cancel_batch_job(configuration: &configuration::Configuration, job_id: &str) -> Result<models::BatchJobOut, Error<JobsApiRoutesBatchCancelBatchJobError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_job_id = job_id;

    let uri_str = format!("{}/v1/batch/jobs/{job_id}/cancel", configuration.base_path, job_id=crate::apis::urlencode(p_path_job_id));
    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BatchJobOut`"))),
            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`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<JobsApiRoutesBatchCancelBatchJobError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Create a new batch job, it will be queued for processing.
pub async fn jobs_api_routes_batch_create_batch_job(configuration: &configuration::Configuration, batch_job_in: models::BatchJobIn) -> Result<models::BatchJobOut, Error<JobsApiRoutesBatchCreateBatchJobError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_body_batch_job_in = batch_job_in;

    let uri_str = format!("{}/v1/batch/jobs", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };
    req_builder = req_builder.json(&p_body_batch_job_in);

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BatchJobOut`"))),
            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`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<JobsApiRoutesBatchCreateBatchJobError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Get a batch job details by its UUID.  Args:     inline: If True, return results inline in the response.
pub async fn jobs_api_routes_batch_get_batch_job(configuration: &configuration::Configuration, job_id: &str, inline: Option<bool>) -> Result<models::BatchJobOut, Error<JobsApiRoutesBatchGetBatchJobError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_job_id = job_id;
    let p_query_inline = inline;

    let uri_str = format!("{}/v1/batch/jobs/{job_id}", configuration.base_path, job_id=crate::apis::urlencode(p_path_job_id));
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref param_value) = p_query_inline {
        req_builder = req_builder.query(&[("inline", &param_value.to_string())]);
    }
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BatchJobOut`"))),
            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`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<JobsApiRoutesBatchGetBatchJobError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Get a list of batch jobs for your organization and user.
pub 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>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_query_page = page;
    let p_query_page_size = page_size;
    let p_query_model = model;
    let p_query_agent_id = agent_id;
    let p_query_metadata = metadata;
    let p_query_created_after = created_after;
    let p_query_created_by_me = created_by_me;
    let p_query_status = status;
    let p_query_order_by = order_by;

    let uri_str = format!("{}/v1/batch/jobs", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref param_value) = p_query_page {
        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_page_size {
        req_builder = req_builder.query(&[("page_size", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_model {
        req_builder = req_builder.query(&[("model", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_agent_id {
        req_builder = req_builder.query(&[("agent_id", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_metadata {
        req_builder = req_builder.query(&[("metadata", &serde_json::to_string(param_value)?)]);
    }
    if let Some(ref param_value) = p_query_created_after {
        req_builder = req_builder.query(&[("created_after", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_created_by_me {
        req_builder = req_builder.query(&[("created_by_me", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_status {
        req_builder = match "multi" {
            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("status".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
            _ => req_builder.query(&[("status", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
        };
    }
    if let Some(ref param_value) = p_query_order_by {
        req_builder = req_builder.query(&[("order_by", &param_value.to_string())]);
    }
    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BatchJobsOut`"))),
            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`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<JobsApiRoutesBatchGetBatchJobsError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}