Skip to main content

langfuse_client_base/apis/
dataset_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_items_create`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum DatasetItemsCreateError {
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_items_delete`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum DatasetItemsDeleteError {
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/// struct for typed errors of method [`dataset_items_get`]
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum DatasetItemsGetError {
44    Status400(serde_json::Value),
45    Status401(serde_json::Value),
46    Status403(serde_json::Value),
47    Status404(serde_json::Value),
48    Status405(serde_json::Value),
49    UnknownValue(serde_json::Value),
50}
51
52/// struct for typed errors of method [`dataset_items_list`]
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum DatasetItemsListError {
56    Status400(serde_json::Value),
57    Status401(serde_json::Value),
58    Status403(serde_json::Value),
59    Status404(serde_json::Value),
60    Status405(serde_json::Value),
61    UnknownValue(serde_json::Value),
62}
63
64/// Create a dataset item
65#[bon::builder]
66pub async fn dataset_items_create(
67    configuration: &configuration::Configuration,
68    create_dataset_item_request: models::CreateDatasetItemRequest,
69) -> Result<models::DatasetItem, Error<DatasetItemsCreateError>> {
70    // add a prefix to parameters to efficiently prevent name collisions
71    let p_body_create_dataset_item_request = create_dataset_item_request;
72
73    let uri_str = format!("{}/api/public/dataset-items", configuration.base_path);
74    let mut req_builder = configuration
75        .client
76        .request(reqwest::Method::POST, &uri_str);
77
78    if let Some(ref user_agent) = configuration.user_agent {
79        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
80    }
81    if let Some(ref auth_conf) = configuration.basic_auth {
82        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
83    };
84    req_builder = req_builder.json(&p_body_create_dataset_item_request);
85
86    let req = req_builder.build()?;
87    let resp = configuration.client.execute(req).await?;
88
89    let status = resp.status();
90    let content_type = resp
91        .headers()
92        .get("content-type")
93        .and_then(|v| v.to_str().ok())
94        .unwrap_or("application/octet-stream");
95    let content_type = super::ContentType::from(content_type);
96
97    if !status.is_client_error() && !status.is_server_error() {
98        let content = resp.text().await?;
99        match content_type {
100            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
101            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DatasetItem`"))),
102            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::DatasetItem`")))),
103        }
104    } else {
105        let content = resp.text().await?;
106        let entity: Option<DatasetItemsCreateError> = serde_json::from_str(&content).ok();
107        Err(Error::ResponseError(ResponseContent {
108            status,
109            content,
110            entity,
111        }))
112    }
113}
114
115/// Delete a dataset item and all its run items. This action is irreversible.
116#[bon::builder]
117pub async fn dataset_items_delete(
118    configuration: &configuration::Configuration,
119    id: &str,
120) -> Result<models::DeleteDatasetItemResponse, Error<DatasetItemsDeleteError>> {
121    // add a prefix to parameters to efficiently prevent name collisions
122    let p_path_id = id;
123
124    let uri_str = format!(
125        "{}/api/public/dataset-items/{id}",
126        configuration.base_path,
127        id = crate::apis::urlencode(p_path_id)
128    );
129    let mut req_builder = configuration
130        .client
131        .request(reqwest::Method::DELETE, &uri_str);
132
133    if let Some(ref user_agent) = configuration.user_agent {
134        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
135    }
136    if let Some(ref auth_conf) = configuration.basic_auth {
137        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
138    };
139
140    let req = req_builder.build()?;
141    let resp = configuration.client.execute(req).await?;
142
143    let status = resp.status();
144    let content_type = resp
145        .headers()
146        .get("content-type")
147        .and_then(|v| v.to_str().ok())
148        .unwrap_or("application/octet-stream");
149    let content_type = super::ContentType::from(content_type);
150
151    if !status.is_client_error() && !status.is_server_error() {
152        let content = resp.text().await?;
153        match content_type {
154            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
155            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteDatasetItemResponse`"))),
156            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::DeleteDatasetItemResponse`")))),
157        }
158    } else {
159        let content = resp.text().await?;
160        let entity: Option<DatasetItemsDeleteError> = serde_json::from_str(&content).ok();
161        Err(Error::ResponseError(ResponseContent {
162            status,
163            content,
164            entity,
165        }))
166    }
167}
168
169/// Get a dataset item
170#[bon::builder]
171pub async fn dataset_items_get(
172    configuration: &configuration::Configuration,
173    id: &str,
174) -> Result<models::DatasetItem, Error<DatasetItemsGetError>> {
175    // add a prefix to parameters to efficiently prevent name collisions
176    let p_path_id = id;
177
178    let uri_str = format!(
179        "{}/api/public/dataset-items/{id}",
180        configuration.base_path,
181        id = crate::apis::urlencode(p_path_id)
182    );
183    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
184
185    if let Some(ref user_agent) = configuration.user_agent {
186        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
187    }
188    if let Some(ref auth_conf) = configuration.basic_auth {
189        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
190    };
191
192    let req = req_builder.build()?;
193    let resp = configuration.client.execute(req).await?;
194
195    let status = resp.status();
196    let content_type = resp
197        .headers()
198        .get("content-type")
199        .and_then(|v| v.to_str().ok())
200        .unwrap_or("application/octet-stream");
201    let content_type = super::ContentType::from(content_type);
202
203    if !status.is_client_error() && !status.is_server_error() {
204        let content = resp.text().await?;
205        match content_type {
206            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
207            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DatasetItem`"))),
208            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::DatasetItem`")))),
209        }
210    } else {
211        let content = resp.text().await?;
212        let entity: Option<DatasetItemsGetError> = serde_json::from_str(&content).ok();
213        Err(Error::ResponseError(ResponseContent {
214            status,
215            content,
216            entity,
217        }))
218    }
219}
220
221/// Get dataset items. Optionally specify a version to get the items as they existed at that point in time. Note: If version parameter is provided, datasetName must also be provided.
222#[bon::builder]
223pub async fn dataset_items_list(
224    configuration: &configuration::Configuration,
225    dataset_name: Option<&str>,
226    source_trace_id: Option<&str>,
227    source_observation_id: Option<&str>,
228    version: Option<String>,
229    page: Option<i32>,
230    limit: Option<i32>,
231) -> Result<models::PaginatedDatasetItems, Error<DatasetItemsListError>> {
232    // add a prefix to parameters to efficiently prevent name collisions
233    let p_query_dataset_name = dataset_name;
234    let p_query_source_trace_id = source_trace_id;
235    let p_query_source_observation_id = source_observation_id;
236    let p_query_version = version;
237    let p_query_page = page;
238    let p_query_limit = limit;
239
240    let uri_str = format!("{}/api/public/dataset-items", configuration.base_path);
241    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
242
243    if let Some(ref param_value) = p_query_dataset_name {
244        req_builder = req_builder.query(&[("datasetName", &param_value.to_string())]);
245    }
246    if let Some(ref param_value) = p_query_source_trace_id {
247        req_builder = req_builder.query(&[("sourceTraceId", &param_value.to_string())]);
248    }
249    if let Some(ref param_value) = p_query_source_observation_id {
250        req_builder = req_builder.query(&[("sourceObservationId", &param_value.to_string())]);
251    }
252    if let Some(ref param_value) = p_query_version {
253        req_builder = req_builder.query(&[("version", &param_value.to_string())]);
254    }
255    if let Some(ref param_value) = p_query_page {
256        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
257    }
258    if let Some(ref param_value) = p_query_limit {
259        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
260    }
261    if let Some(ref user_agent) = configuration.user_agent {
262        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
263    }
264    if let Some(ref auth_conf) = configuration.basic_auth {
265        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
266    };
267
268    let req = req_builder.build()?;
269    let resp = configuration.client.execute(req).await?;
270
271    let status = resp.status();
272    let content_type = resp
273        .headers()
274        .get("content-type")
275        .and_then(|v| v.to_str().ok())
276        .unwrap_or("application/octet-stream");
277    let content_type = super::ContentType::from(content_type);
278
279    if !status.is_client_error() && !status.is_server_error() {
280        let content = resp.text().await?;
281        match content_type {
282            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
283            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PaginatedDatasetItems`"))),
284            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::PaginatedDatasetItems`")))),
285        }
286    } else {
287        let content = resp.text().await?;
288        let entity: Option<DatasetItemsListError> = serde_json::from_str(&content).ok();
289        Err(Error::ResponseError(ResponseContent {
290            status,
291            content,
292            entity,
293        }))
294    }
295}