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_fine_tuning_cancel_fine_tuning_job`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum JobsApiRoutesFineTuningCancelFineTuningJobError {
    UnknownValue(serde_json::Value),
}

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

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

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

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


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

    let uri_str = format!("{}/v1/fine_tuning/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::Response1`"))),
            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::Response1`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<JobsApiRoutesFineTuningCancelFineTuningJobError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Create a new fine-tuning job, it will be queued for processing.
pub async fn jobs_api_routes_fine_tuning_create_fine_tuning_job(configuration: &configuration::Configuration, job_in: models::JobIn, dry_run: Option<bool>) -> Result<models::Response, Error<JobsApiRoutesFineTuningCreateFineTuningJobError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_body_job_in = job_in;
    let p_query_dry_run = dry_run;

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

    if let Some(ref param_value) = p_query_dry_run {
        req_builder = req_builder.query(&[("dry_run", &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());
    };
    req_builder = req_builder.json(&p_body_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::Response`"))),
            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::Response`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<JobsApiRoutesFineTuningCreateFineTuningJobError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Get a fine-tuned job details by its UUID.
pub async fn jobs_api_routes_fine_tuning_get_fine_tuning_job(configuration: &configuration::Configuration, job_id: &str) -> Result<models::Response1, Error<JobsApiRoutesFineTuningGetFineTuningJobError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_job_id = job_id;

    let uri_str = format!("{}/v1/fine_tuning/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 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::Response1`"))),
            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::Response1`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<JobsApiRoutesFineTuningGetFineTuningJobError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Get a list of fine-tuning jobs for your organization and user.
pub async fn jobs_api_routes_fine_tuning_get_fine_tuning_jobs(configuration: &configuration::Configuration, page: Option<i32>, page_size: Option<i32>, model: Option<&str>, created_after: Option<String>, created_before: Option<String>, created_by_me: Option<bool>, status: Option<&str>, wandb_project: Option<&str>, wandb_name: Option<&str>, suffix: Option<&str>) -> Result<models::JobsOut, Error<JobsApiRoutesFineTuningGetFineTuningJobsError>> {
    // 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_created_after = created_after;
    let p_query_created_before = created_before;
    let p_query_created_by_me = created_by_me;
    let p_query_status = status;
    let p_query_wandb_project = wandb_project;
    let p_query_wandb_name = wandb_name;
    let p_query_suffix = suffix;

    let uri_str = format!("{}/v1/fine_tuning/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_created_after {
        req_builder = req_builder.query(&[("created_after", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_created_before {
        req_builder = req_builder.query(&[("created_before", &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 = req_builder.query(&[("status", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_wandb_project {
        req_builder = req_builder.query(&[("wandb_project", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_wandb_name {
        req_builder = req_builder.query(&[("wandb_name", &param_value.to_string())]);
    }
    if let Some(ref param_value) = p_query_suffix {
        req_builder = req_builder.query(&[("suffix", &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::JobsOut`"))),
            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::JobsOut`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<JobsApiRoutesFineTuningGetFineTuningJobsError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}

/// Request the start of a validated fine tuning job.
pub async fn jobs_api_routes_fine_tuning_start_fine_tuning_job(configuration: &configuration::Configuration, job_id: &str) -> Result<models::Response1, Error<JobsApiRoutesFineTuningStartFineTuningJobError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_path_job_id = job_id;

    let uri_str = format!("{}/v1/fine_tuning/jobs/{job_id}/start", 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::Response1`"))),
            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::Response1`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<JobsApiRoutesFineTuningStartFineTuningJobError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent { status, content, entity }))
    }
}