langfuse_client_base/apis/
dataset_run_items_api.rs

1/*
2 * langfuse
3 *
4 * ## Authentication  Authenticate with the API using [Basic Auth](https://en.wikipedia.org/wiki/Basic_access_authentication), get API keys in the project settings:  - username: Langfuse Public Key - password: Langfuse Secret Key  ## Exports  - OpenAPI spec: https://cloud.langfuse.com/generated/api/openapi.yml - Postman collection: https://cloud.langfuse.com/generated/postman/collection.json
5 *
6 * The version of the OpenAPI document:
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for typed errors of method [`dataset_run_items_create`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum DatasetRunItemsCreateError {
20    Status400(serde_json::Value),
21    Status401(serde_json::Value),
22    Status403(serde_json::Value),
23    Status404(serde_json::Value),
24    Status405(serde_json::Value),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`dataset_run_items_list`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum DatasetRunItemsListError {
32    Status400(serde_json::Value),
33    Status401(serde_json::Value),
34    Status403(serde_json::Value),
35    Status404(serde_json::Value),
36    Status405(serde_json::Value),
37    UnknownValue(serde_json::Value),
38}
39
40/// Create a dataset run item
41#[bon::builder]
42pub async fn dataset_run_items_create(
43    configuration: &configuration::Configuration,
44    create_dataset_run_item_request: models::CreateDatasetRunItemRequest,
45) -> Result<models::DatasetRunItem, Error<DatasetRunItemsCreateError>> {
46    // add a prefix to parameters to efficiently prevent name collisions
47    let p_body_create_dataset_run_item_request = create_dataset_run_item_request;
48
49    let uri_str = format!("{}/api/public/dataset-run-items", configuration.base_path);
50    let mut req_builder = configuration
51        .client
52        .request(reqwest::Method::POST, &uri_str);
53
54    if let Some(ref user_agent) = configuration.user_agent {
55        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
56    }
57    if let Some(ref auth_conf) = configuration.basic_auth {
58        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
59    };
60    req_builder = req_builder.json(&p_body_create_dataset_run_item_request);
61
62    let req = req_builder.build()?;
63    let resp = configuration.client.execute(req).await?;
64
65    let status = resp.status();
66    let content_type = resp
67        .headers()
68        .get("content-type")
69        .and_then(|v| v.to_str().ok())
70        .unwrap_or("application/octet-stream");
71    let content_type = super::ContentType::from(content_type);
72
73    if !status.is_client_error() && !status.is_server_error() {
74        let content = resp.text().await?;
75        match content_type {
76            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
77            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DatasetRunItem`"))),
78            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::DatasetRunItem`")))),
79        }
80    } else {
81        let content = resp.text().await?;
82        let entity: Option<DatasetRunItemsCreateError> = serde_json::from_str(&content).ok();
83        Err(Error::ResponseError(ResponseContent {
84            status,
85            content,
86            entity,
87        }))
88    }
89}
90
91/// List dataset run items
92#[bon::builder]
93pub async fn dataset_run_items_list(
94    configuration: &configuration::Configuration,
95    dataset_id: &str,
96    run_name: &str,
97    page: Option<i32>,
98    limit: Option<i32>,
99) -> Result<models::PaginatedDatasetRunItems, Error<DatasetRunItemsListError>> {
100    // add a prefix to parameters to efficiently prevent name collisions
101    let p_query_dataset_id = dataset_id;
102    let p_query_run_name = run_name;
103    let p_query_page = page;
104    let p_query_limit = limit;
105
106    let uri_str = format!("{}/api/public/dataset-run-items", configuration.base_path);
107    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
108
109    req_builder = req_builder.query(&[("datasetId", &p_query_dataset_id.to_string())]);
110    req_builder = req_builder.query(&[("runName", &p_query_run_name.to_string())]);
111    if let Some(ref param_value) = p_query_page {
112        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
113    }
114    if let Some(ref param_value) = p_query_limit {
115        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
116    }
117    if let Some(ref user_agent) = configuration.user_agent {
118        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
119    }
120    if let Some(ref auth_conf) = configuration.basic_auth {
121        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
122    };
123
124    let req = req_builder.build()?;
125    let resp = configuration.client.execute(req).await?;
126
127    let status = resp.status();
128    let content_type = resp
129        .headers()
130        .get("content-type")
131        .and_then(|v| v.to_str().ok())
132        .unwrap_or("application/octet-stream");
133    let content_type = super::ContentType::from(content_type);
134
135    if !status.is_client_error() && !status.is_server_error() {
136        let content = resp.text().await?;
137        match content_type {
138            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
139            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PaginatedDatasetRunItems`"))),
140            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::PaginatedDatasetRunItems`")))),
141        }
142    } else {
143        let content = resp.text().await?;
144        let entity: Option<DatasetRunItemsListError> = serde_json::from_str(&content).ok();
145        Err(Error::ResponseError(ResponseContent {
146            status,
147            content,
148            entity,
149        }))
150    }
151}