langgraph_api/generated/apis/
stateless_runs_api.rs

1/*
2 * LangSmith Deployment
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: 0.1.0
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{ContentType, Error, UploadFile, configuration};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{Deserialize, Serialize, de::Error as _};
15
16/// struct for typed errors of method [`run_batch_stateless_runs_post`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum RunBatchStatelessRunsPostError {
20    Status404(String),
21    Status409(String),
22    Status422(String),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`run_stateless_runs_post`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum RunStatelessRunsPostError {
30    Status404(String),
31    Status409(String),
32    Status422(String),
33    UnknownValue(serde_json::Value),
34}
35
36/// struct for typed errors of method [`stream_run_stateless_runs_stream_post`]
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum StreamRunStatelessRunsStreamPostError {
40    Status404(String),
41    Status409(String),
42    Status422(String),
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`wait_run_stateless_runs_wait_post`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum WaitRunStatelessRunsWaitPostError {
50    Status404(String),
51    Status409(String),
52    Status422(String),
53    UnknownValue(serde_json::Value),
54}
55
56/// Create a batch of runs and return immediately.
57pub fn run_batch_stateless_runs_post_request_builder(
58    configuration: &configuration::Configuration,
59    run_create_stateless: Vec<models::RunCreateStateless>,
60) -> Result<reqwest::RequestBuilder, Error<serde_json::Error>> {
61    // add a prefix to parameters to efficiently prevent name collisions
62    let p_body_run_create_stateless = run_create_stateless;
63
64    let uri_str = format!("{}/runs/batch", configuration.base_path);
65    let mut req_builder = configuration
66        .client
67        .request(reqwest::Method::POST, &uri_str);
68
69    if let Some(ref user_agent) = configuration.user_agent {
70        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
71    }
72    req_builder = req_builder.json(&p_body_run_create_stateless);
73
74    Ok(req_builder)
75}
76
77pub async fn run_batch_stateless_runs_post(
78    configuration: &configuration::Configuration,
79    run_create_stateless: Vec<models::RunCreateStateless>,
80) -> Result<serde_json::Value, Error<RunBatchStatelessRunsPostError>> {
81    let req_builder =
82        run_batch_stateless_runs_post_request_builder(configuration, run_create_stateless)
83            .map_err(super::map_request_builder_error)?;
84    let req = req_builder.build()?;
85    let resp = configuration.client.execute(req).await?;
86
87    let status = resp.status();
88    let content_type = resp
89        .headers()
90        .get("content-type")
91        .and_then(|v| v.to_str().ok())
92        .unwrap_or("application/octet-stream");
93    let content_type = super::ContentType::from(content_type);
94
95    if !status.is_client_error() && !status.is_server_error() {
96        let content = resp.text().await?;
97        match content_type {
98            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
99            ContentType::Text => Err(Error::from(serde_json::Error::custom(
100                "Received `text/plain` content type response that cannot be converted to `serde_json::Value`",
101            ))),
102            ContentType::Unsupported(unknown_type) => {
103                Err(Error::from(serde_json::Error::custom(format!(
104                    "Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`"
105                ))))
106            }
107        }
108    } else {
109        let content = resp.text().await?;
110        let entity: Option<RunBatchStatelessRunsPostError> = serde_json::from_str(&content).ok();
111        Err(Error::ResponseError(ResponseContent {
112            status,
113            content,
114            entity,
115        }))
116    }
117}
118
119/// Create a run and return the run ID immediately. Don't wait for the final run output.
120pub fn run_stateless_runs_post_request_builder(
121    configuration: &configuration::Configuration,
122    run_create_stateless: models::RunCreateStateless,
123) -> Result<reqwest::RequestBuilder, Error<serde_json::Error>> {
124    // add a prefix to parameters to efficiently prevent name collisions
125    let p_body_run_create_stateless = run_create_stateless;
126
127    let uri_str = format!("{}/runs", configuration.base_path);
128    let mut req_builder = configuration
129        .client
130        .request(reqwest::Method::POST, &uri_str);
131
132    if let Some(ref user_agent) = configuration.user_agent {
133        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
134    }
135    req_builder = req_builder.json(&p_body_run_create_stateless);
136
137    Ok(req_builder)
138}
139
140pub async fn run_stateless_runs_post(
141    configuration: &configuration::Configuration,
142    run_create_stateless: models::RunCreateStateless,
143) -> Result<serde_json::Value, Error<RunStatelessRunsPostError>> {
144    let req_builder = run_stateless_runs_post_request_builder(configuration, run_create_stateless)
145        .map_err(super::map_request_builder_error)?;
146    let req = req_builder.build()?;
147    let resp = configuration.client.execute(req).await?;
148
149    let status = resp.status();
150    let content_type = resp
151        .headers()
152        .get("content-type")
153        .and_then(|v| v.to_str().ok())
154        .unwrap_or("application/octet-stream");
155    let content_type = super::ContentType::from(content_type);
156
157    if !status.is_client_error() && !status.is_server_error() {
158        let content = resp.text().await?;
159        match content_type {
160            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
161            ContentType::Text => Err(Error::from(serde_json::Error::custom(
162                "Received `text/plain` content type response that cannot be converted to `serde_json::Value`",
163            ))),
164            ContentType::Unsupported(unknown_type) => {
165                Err(Error::from(serde_json::Error::custom(format!(
166                    "Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`"
167                ))))
168            }
169        }
170    } else {
171        let content = resp.text().await?;
172        let entity: Option<RunStatelessRunsPostError> = serde_json::from_str(&content).ok();
173        Err(Error::ResponseError(ResponseContent {
174            status,
175            content,
176            entity,
177        }))
178    }
179}
180
181/// Create a run and stream the output.
182pub fn stream_run_stateless_runs_stream_post_request_builder(
183    configuration: &configuration::Configuration,
184    run_create_stateless: models::RunCreateStateless,
185) -> Result<reqwest::RequestBuilder, Error<serde_json::Error>> {
186    // add a prefix to parameters to efficiently prevent name collisions
187    let p_body_run_create_stateless = run_create_stateless;
188
189    let uri_str = format!("{}/runs/stream", configuration.base_path);
190    let mut req_builder = configuration
191        .client
192        .request(reqwest::Method::POST, &uri_str);
193
194    if let Some(ref user_agent) = configuration.user_agent {
195        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
196    }
197    req_builder = req_builder.json(&p_body_run_create_stateless);
198
199    Ok(req_builder)
200}
201
202pub async fn stream_run_stateless_runs_stream_post(
203    configuration: &configuration::Configuration,
204    run_create_stateless: models::RunCreateStateless,
205) -> Result<String, Error<StreamRunStatelessRunsStreamPostError>> {
206    let req_builder =
207        stream_run_stateless_runs_stream_post_request_builder(configuration, run_create_stateless)
208            .map_err(super::map_request_builder_error)?;
209    let req = req_builder.build()?;
210    let resp = configuration.client.execute(req).await?;
211
212    let status = resp.status();
213    let content_type = resp
214        .headers()
215        .get("content-type")
216        .and_then(|v| v.to_str().ok())
217        .unwrap_or("application/octet-stream");
218    let content_type = super::ContentType::from(content_type);
219
220    if !status.is_client_error() && !status.is_server_error() {
221        let content = resp.text().await?;
222        match content_type {
223            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
224            ContentType::Text => Err(Error::from(serde_json::Error::custom(
225                "Received `text/plain` content type response that cannot be converted to `String`",
226            ))),
227            ContentType::Unsupported(unknown_type) => {
228                Err(Error::from(serde_json::Error::custom(format!(
229                    "Received `{unknown_type}` content type response that cannot be converted to `String`"
230                ))))
231            }
232        }
233    } else {
234        let content = resp.text().await?;
235        let entity: Option<StreamRunStatelessRunsStreamPostError> =
236            serde_json::from_str(&content).ok();
237        Err(Error::ResponseError(ResponseContent {
238            status,
239            content,
240            entity,
241        }))
242    }
243}
244
245/// Create a run, wait for the final output and then return it.
246pub fn wait_run_stateless_runs_wait_post_request_builder(
247    configuration: &configuration::Configuration,
248    run_create_stateless: models::RunCreateStateless,
249) -> Result<reqwest::RequestBuilder, Error<serde_json::Error>> {
250    // add a prefix to parameters to efficiently prevent name collisions
251    let p_body_run_create_stateless = run_create_stateless;
252
253    let uri_str = format!("{}/runs/wait", configuration.base_path);
254    let mut req_builder = configuration
255        .client
256        .request(reqwest::Method::POST, &uri_str);
257
258    if let Some(ref user_agent) = configuration.user_agent {
259        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
260    }
261    req_builder = req_builder.json(&p_body_run_create_stateless);
262
263    Ok(req_builder)
264}
265
266pub async fn wait_run_stateless_runs_wait_post(
267    configuration: &configuration::Configuration,
268    run_create_stateless: models::RunCreateStateless,
269) -> Result<serde_json::Value, Error<WaitRunStatelessRunsWaitPostError>> {
270    let req_builder =
271        wait_run_stateless_runs_wait_post_request_builder(configuration, run_create_stateless)
272            .map_err(super::map_request_builder_error)?;
273    let req = req_builder.build()?;
274    let resp = configuration.client.execute(req).await?;
275
276    let status = resp.status();
277    let content_type = resp
278        .headers()
279        .get("content-type")
280        .and_then(|v| v.to_str().ok())
281        .unwrap_or("application/octet-stream");
282    let content_type = super::ContentType::from(content_type);
283
284    if !status.is_client_error() && !status.is_server_error() {
285        let content = resp.text().await?;
286        match content_type {
287            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
288            ContentType::Text => Err(Error::from(serde_json::Error::custom(
289                "Received `text/plain` content type response that cannot be converted to `serde_json::Value`",
290            ))),
291            ContentType::Unsupported(unknown_type) => {
292                Err(Error::from(serde_json::Error::custom(format!(
293                    "Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`"
294                ))))
295            }
296        }
297    } else {
298        let content = resp.text().await?;
299        let entity: Option<WaitRunStatelessRunsWaitPostError> = serde_json::from_str(&content).ok();
300        Err(Error::ResponseError(ResponseContent {
301            status,
302            content,
303            entity,
304        }))
305    }
306}