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
41pub async fn dataset_run_items_create(
42    configuration: &configuration::Configuration,
43    create_dataset_run_item_request: models::CreateDatasetRunItemRequest,
44) -> Result<models::DatasetRunItem, Error<DatasetRunItemsCreateError>> {
45    // add a prefix to parameters to efficiently prevent name collisions
46    let p_body_create_dataset_run_item_request = create_dataset_run_item_request;
47
48    let uri_str = format!("{}/api/public/dataset-run-items", configuration.base_path);
49    let mut req_builder = configuration
50        .client
51        .request(reqwest::Method::POST, &uri_str);
52
53    if let Some(ref user_agent) = configuration.user_agent {
54        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
55    }
56    if let Some(ref auth_conf) = configuration.basic_auth {
57        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
58    };
59    req_builder = req_builder.json(&p_body_create_dataset_run_item_request);
60
61    let req = req_builder.build()?;
62    let resp = configuration.client.execute(req).await?;
63
64    let status = resp.status();
65    let content_type = resp
66        .headers()
67        .get("content-type")
68        .and_then(|v| v.to_str().ok())
69        .unwrap_or("application/octet-stream");
70    let content_type = super::ContentType::from(content_type);
71
72    if !status.is_client_error() && !status.is_server_error() {
73        let content = resp.text().await?;
74        match content_type {
75            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
76            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DatasetRunItem`"))),
77            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`")))),
78        }
79    } else {
80        let content = resp.text().await?;
81        let entity: Option<DatasetRunItemsCreateError> = serde_json::from_str(&content).ok();
82        Err(Error::ResponseError(ResponseContent {
83            status,
84            content,
85            entity,
86        }))
87    }
88}
89
90/// List dataset run items
91pub async fn dataset_run_items_list(
92    configuration: &configuration::Configuration,
93    dataset_id: &str,
94    run_name: &str,
95    page: Option<i32>,
96    limit: Option<i32>,
97) -> Result<models::PaginatedDatasetRunItems, Error<DatasetRunItemsListError>> {
98    // add a prefix to parameters to efficiently prevent name collisions
99    let p_query_dataset_id = dataset_id;
100    let p_query_run_name = run_name;
101    let p_query_page = page;
102    let p_query_limit = limit;
103
104    let uri_str = format!("{}/api/public/dataset-run-items", configuration.base_path);
105    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
106
107    req_builder = req_builder.query(&[("datasetId", &p_query_dataset_id.to_string())]);
108    req_builder = req_builder.query(&[("runName", &p_query_run_name.to_string())]);
109    if let Some(ref param_value) = p_query_page {
110        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
111    }
112    if let Some(ref param_value) = p_query_limit {
113        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
114    }
115    if let Some(ref user_agent) = configuration.user_agent {
116        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
117    }
118    if let Some(ref auth_conf) = configuration.basic_auth {
119        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
120    };
121
122    let req = req_builder.build()?;
123    let resp = configuration.client.execute(req).await?;
124
125    let status = resp.status();
126    let content_type = resp
127        .headers()
128        .get("content-type")
129        .and_then(|v| v.to_str().ok())
130        .unwrap_or("application/octet-stream");
131    let content_type = super::ContentType::from(content_type);
132
133    if !status.is_client_error() && !status.is_server_error() {
134        let content = resp.text().await?;
135        match content_type {
136            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
137            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PaginatedDatasetRunItems`"))),
138            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`")))),
139        }
140    } else {
141        let content = resp.text().await?;
142        let entity: Option<DatasetRunItemsListError> = serde_json::from_str(&content).ok();
143        Err(Error::ResponseError(ResponseContent {
144            status,
145            content,
146            entity,
147        }))
148    }
149}