langgraph-api 0.1.1

Rust Client API of LangGraph
Documentation
/*
 * LangSmith Deployment
 *
 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
 *
 * The version of the OpenAPI document: 0.1.0
 *
 * Generated by: https://openapi-generator.tech
 */

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

/// struct for typed errors of method [`run_batch_stateless_runs_post`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RunBatchStatelessRunsPostError {
    Status404(String),
    Status409(String),
    Status422(String),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`run_stateless_runs_post`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RunStatelessRunsPostError {
    Status404(String),
    Status409(String),
    Status422(String),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`stream_run_stateless_runs_stream_post`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum StreamRunStatelessRunsStreamPostError {
    Status404(String),
    Status409(String),
    Status422(String),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`wait_run_stateless_runs_wait_post`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WaitRunStatelessRunsWaitPostError {
    Status404(String),
    Status409(String),
    Status422(String),
    UnknownValue(serde_json::Value),
}

/// Create a batch of runs and return immediately.
pub fn run_batch_stateless_runs_post_request_builder(
    configuration: &configuration::Configuration,
    run_create_stateless: Vec<models::RunCreateStateless>,
) -> Result<reqwest::RequestBuilder, Error<serde_json::Error>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_body_run_create_stateless = run_create_stateless;

    let uri_str = format!("{}/runs/batch", 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());
    }
    req_builder = req_builder.json(&p_body_run_create_stateless);

    Ok(req_builder)
}

pub async fn run_batch_stateless_runs_post(
    configuration: &configuration::Configuration,
    run_create_stateless: Vec<models::RunCreateStateless>,
) -> Result<serde_json::Value, Error<RunBatchStatelessRunsPostError>> {
    let req_builder =
        run_batch_stateless_runs_post_request_builder(configuration, run_create_stateless)
            .map_err(super::map_request_builder_error)?;
    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 => Err(Error::from(serde_json::Error::custom(
                "Received `text/plain` content type response that cannot be converted to `serde_json::Value`",
            ))),
            ContentType::Unsupported(unknown_type) => {
                Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`"
                ))))
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<RunBatchStatelessRunsPostError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Create a run and return the run ID immediately. Don't wait for the final run output.
pub fn run_stateless_runs_post_request_builder(
    configuration: &configuration::Configuration,
    run_create_stateless: models::RunCreateStateless,
) -> Result<reqwest::RequestBuilder, Error<serde_json::Error>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_body_run_create_stateless = run_create_stateless;

    let uri_str = format!("{}/runs", 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());
    }
    req_builder = req_builder.json(&p_body_run_create_stateless);

    Ok(req_builder)
}

pub async fn run_stateless_runs_post(
    configuration: &configuration::Configuration,
    run_create_stateless: models::RunCreateStateless,
) -> Result<serde_json::Value, Error<RunStatelessRunsPostError>> {
    let req_builder = run_stateless_runs_post_request_builder(configuration, run_create_stateless)
        .map_err(super::map_request_builder_error)?;
    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 => Err(Error::from(serde_json::Error::custom(
                "Received `text/plain` content type response that cannot be converted to `serde_json::Value`",
            ))),
            ContentType::Unsupported(unknown_type) => {
                Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`"
                ))))
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<RunStatelessRunsPostError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Create a run and stream the output.
pub fn stream_run_stateless_runs_stream_post_request_builder(
    configuration: &configuration::Configuration,
    run_create_stateless: models::RunCreateStateless,
) -> Result<reqwest::RequestBuilder, Error<serde_json::Error>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_body_run_create_stateless = run_create_stateless;

    let uri_str = format!("{}/runs/stream", 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());
    }
    req_builder = req_builder.json(&p_body_run_create_stateless);

    Ok(req_builder)
}

pub async fn stream_run_stateless_runs_stream_post(
    configuration: &configuration::Configuration,
    run_create_stateless: models::RunCreateStateless,
) -> Result<String, Error<StreamRunStatelessRunsStreamPostError>> {
    let req_builder =
        stream_run_stateless_runs_stream_post_request_builder(configuration, run_create_stateless)
            .map_err(super::map_request_builder_error)?;
    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 => Err(Error::from(serde_json::Error::custom(
                "Received `text/plain` content type response that cannot be converted to `String`",
            ))),
            ContentType::Unsupported(unknown_type) => {
                Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to `String`"
                ))))
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<StreamRunStatelessRunsStreamPostError> =
            serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Create a run, wait for the final output and then return it.
pub fn wait_run_stateless_runs_wait_post_request_builder(
    configuration: &configuration::Configuration,
    run_create_stateless: models::RunCreateStateless,
) -> Result<reqwest::RequestBuilder, Error<serde_json::Error>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_body_run_create_stateless = run_create_stateless;

    let uri_str = format!("{}/runs/wait", 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());
    }
    req_builder = req_builder.json(&p_body_run_create_stateless);

    Ok(req_builder)
}

pub async fn wait_run_stateless_runs_wait_post(
    configuration: &configuration::Configuration,
    run_create_stateless: models::RunCreateStateless,
) -> Result<serde_json::Value, Error<WaitRunStatelessRunsWaitPostError>> {
    let req_builder =
        wait_run_stateless_runs_wait_post_request_builder(configuration, run_create_stateless)
            .map_err(super::map_request_builder_error)?;
    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 => Err(Error::from(serde_json::Error::custom(
                "Received `text/plain` content type response that cannot be converted to `serde_json::Value`",
            ))),
            ContentType::Unsupported(unknown_type) => {
                Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`"
                ))))
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<WaitRunStatelessRunsWaitPostError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}