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