langfuse_client/apis/
datasets_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
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`datasets_create`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DatasetsCreateError {
22    Status400(serde_json::Value),
23    Status401(serde_json::Value),
24    Status403(serde_json::Value),
25    Status404(serde_json::Value),
26    Status405(serde_json::Value),
27    UnknownValue(serde_json::Value),
28}
29
30/// struct for typed errors of method [`datasets_delete_run`]
31#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum DatasetsDeleteRunError {
34    Status400(serde_json::Value),
35    Status401(serde_json::Value),
36    Status403(serde_json::Value),
37    Status404(serde_json::Value),
38    Status405(serde_json::Value),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`datasets_get`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum DatasetsGetError {
46    Status400(serde_json::Value),
47    Status401(serde_json::Value),
48    Status403(serde_json::Value),
49    Status404(serde_json::Value),
50    Status405(serde_json::Value),
51    UnknownValue(serde_json::Value),
52}
53
54/// struct for typed errors of method [`datasets_get_run`]
55#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(untagged)]
57pub enum DatasetsGetRunError {
58    Status400(serde_json::Value),
59    Status401(serde_json::Value),
60    Status403(serde_json::Value),
61    Status404(serde_json::Value),
62    Status405(serde_json::Value),
63    UnknownValue(serde_json::Value),
64}
65
66/// struct for typed errors of method [`datasets_get_runs`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum DatasetsGetRunsError {
70    Status400(serde_json::Value),
71    Status401(serde_json::Value),
72    Status403(serde_json::Value),
73    Status404(serde_json::Value),
74    Status405(serde_json::Value),
75    UnknownValue(serde_json::Value),
76}
77
78/// struct for typed errors of method [`datasets_list`]
79#[derive(Debug, Clone, Serialize, Deserialize)]
80#[serde(untagged)]
81pub enum DatasetsListError {
82    Status400(serde_json::Value),
83    Status401(serde_json::Value),
84    Status403(serde_json::Value),
85    Status404(serde_json::Value),
86    Status405(serde_json::Value),
87    UnknownValue(serde_json::Value),
88}
89
90
91/// Create a dataset
92pub async fn datasets_create(configuration: &configuration::Configuration, create_dataset_request: models::CreateDatasetRequest) -> Result<models::Dataset, Error<DatasetsCreateError>> {
93    // add a prefix to parameters to efficiently prevent name collisions
94    let p_create_dataset_request = create_dataset_request;
95
96    let uri_str = format!("{}/api/public/v2/datasets", configuration.base_path);
97    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
98
99    if let Some(ref user_agent) = configuration.user_agent {
100        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
101    }
102    if let Some(ref auth_conf) = configuration.basic_auth {
103        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
104    };
105    req_builder = req_builder.json(&p_create_dataset_request);
106
107    let req = req_builder.build()?;
108    let resp = configuration.client.execute(req).await?;
109
110    let status = resp.status();
111    let content_type = resp
112        .headers()
113        .get("content-type")
114        .and_then(|v| v.to_str().ok())
115        .unwrap_or("application/octet-stream");
116    let content_type = super::ContentType::from(content_type);
117
118    if !status.is_client_error() && !status.is_server_error() {
119        let content = resp.text().await?;
120        match content_type {
121            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
122            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Dataset`"))),
123            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::Dataset`")))),
124        }
125    } else {
126        let content = resp.text().await?;
127        let entity: Option<DatasetsCreateError> = serde_json::from_str(&content).ok();
128        Err(Error::ResponseError(ResponseContent { status, content, entity }))
129    }
130}
131
132/// Delete a dataset run and all its run items. This action is irreversible.
133pub async fn datasets_delete_run(configuration: &configuration::Configuration, dataset_name: &str, run_name: &str) -> Result<models::DeleteDatasetRunResponse, Error<DatasetsDeleteRunError>> {
134    // add a prefix to parameters to efficiently prevent name collisions
135    let p_dataset_name = dataset_name;
136    let p_run_name = run_name;
137
138    let uri_str = format!("{}/api/public/datasets/{datasetName}/runs/{runName}", configuration.base_path, datasetName=crate::apis::urlencode(p_dataset_name), runName=crate::apis::urlencode(p_run_name));
139    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
140
141    if let Some(ref user_agent) = configuration.user_agent {
142        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
143    }
144    if let Some(ref auth_conf) = configuration.basic_auth {
145        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
146    };
147
148    let req = req_builder.build()?;
149    let resp = configuration.client.execute(req).await?;
150
151    let status = resp.status();
152    let content_type = resp
153        .headers()
154        .get("content-type")
155        .and_then(|v| v.to_str().ok())
156        .unwrap_or("application/octet-stream");
157    let content_type = super::ContentType::from(content_type);
158
159    if !status.is_client_error() && !status.is_server_error() {
160        let content = resp.text().await?;
161        match content_type {
162            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
163            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteDatasetRunResponse`"))),
164            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::DeleteDatasetRunResponse`")))),
165        }
166    } else {
167        let content = resp.text().await?;
168        let entity: Option<DatasetsDeleteRunError> = serde_json::from_str(&content).ok();
169        Err(Error::ResponseError(ResponseContent { status, content, entity }))
170    }
171}
172
173/// Get a dataset
174pub async fn datasets_get(configuration: &configuration::Configuration, dataset_name: &str) -> Result<models::Dataset, Error<DatasetsGetError>> {
175    // add a prefix to parameters to efficiently prevent name collisions
176    let p_dataset_name = dataset_name;
177
178    let uri_str = format!("{}/api/public/v2/datasets/{datasetName}", configuration.base_path, datasetName=crate::apis::urlencode(p_dataset_name));
179    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
180
181    if let Some(ref user_agent) = configuration.user_agent {
182        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
183    }
184    if let Some(ref auth_conf) = configuration.basic_auth {
185        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
186    };
187
188    let req = req_builder.build()?;
189    let resp = configuration.client.execute(req).await?;
190
191    let status = resp.status();
192    let content_type = resp
193        .headers()
194        .get("content-type")
195        .and_then(|v| v.to_str().ok())
196        .unwrap_or("application/octet-stream");
197    let content_type = super::ContentType::from(content_type);
198
199    if !status.is_client_error() && !status.is_server_error() {
200        let content = resp.text().await?;
201        match content_type {
202            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
203            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Dataset`"))),
204            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::Dataset`")))),
205        }
206    } else {
207        let content = resp.text().await?;
208        let entity: Option<DatasetsGetError> = serde_json::from_str(&content).ok();
209        Err(Error::ResponseError(ResponseContent { status, content, entity }))
210    }
211}
212
213/// Get a dataset run and its items
214pub async fn datasets_get_run(configuration: &configuration::Configuration, dataset_name: &str, run_name: &str) -> Result<models::DatasetRunWithItems, Error<DatasetsGetRunError>> {
215    // add a prefix to parameters to efficiently prevent name collisions
216    let p_dataset_name = dataset_name;
217    let p_run_name = run_name;
218
219    let uri_str = format!("{}/api/public/datasets/{datasetName}/runs/{runName}", configuration.base_path, datasetName=crate::apis::urlencode(p_dataset_name), runName=crate::apis::urlencode(p_run_name));
220    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
221
222    if let Some(ref user_agent) = configuration.user_agent {
223        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
224    }
225    if let Some(ref auth_conf) = configuration.basic_auth {
226        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
227    };
228
229    let req = req_builder.build()?;
230    let resp = configuration.client.execute(req).await?;
231
232    let status = resp.status();
233    let content_type = resp
234        .headers()
235        .get("content-type")
236        .and_then(|v| v.to_str().ok())
237        .unwrap_or("application/octet-stream");
238    let content_type = super::ContentType::from(content_type);
239
240    if !status.is_client_error() && !status.is_server_error() {
241        let content = resp.text().await?;
242        match content_type {
243            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
244            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DatasetRunWithItems`"))),
245            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::DatasetRunWithItems`")))),
246        }
247    } else {
248        let content = resp.text().await?;
249        let entity: Option<DatasetsGetRunError> = serde_json::from_str(&content).ok();
250        Err(Error::ResponseError(ResponseContent { status, content, entity }))
251    }
252}
253
254/// Get dataset runs
255pub async fn datasets_get_runs(configuration: &configuration::Configuration, dataset_name: &str, page: Option<i32>, limit: Option<i32>) -> Result<models::PaginatedDatasetRuns, Error<DatasetsGetRunsError>> {
256    // add a prefix to parameters to efficiently prevent name collisions
257    let p_dataset_name = dataset_name;
258    let p_page = page;
259    let p_limit = limit;
260
261    let uri_str = format!("{}/api/public/datasets/{datasetName}/runs", configuration.base_path, datasetName=crate::apis::urlencode(p_dataset_name));
262    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
263
264    if let Some(ref param_value) = p_page {
265        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
266    }
267    if let Some(ref param_value) = p_limit {
268        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
269    }
270    if let Some(ref user_agent) = configuration.user_agent {
271        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
272    }
273    if let Some(ref auth_conf) = configuration.basic_auth {
274        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
275    };
276
277    let req = req_builder.build()?;
278    let resp = configuration.client.execute(req).await?;
279
280    let status = resp.status();
281    let content_type = resp
282        .headers()
283        .get("content-type")
284        .and_then(|v| v.to_str().ok())
285        .unwrap_or("application/octet-stream");
286    let content_type = super::ContentType::from(content_type);
287
288    if !status.is_client_error() && !status.is_server_error() {
289        let content = resp.text().await?;
290        match content_type {
291            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
292            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PaginatedDatasetRuns`"))),
293            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::PaginatedDatasetRuns`")))),
294        }
295    } else {
296        let content = resp.text().await?;
297        let entity: Option<DatasetsGetRunsError> = serde_json::from_str(&content).ok();
298        Err(Error::ResponseError(ResponseContent { status, content, entity }))
299    }
300}
301
302/// Get all datasets
303pub async fn datasets_list(configuration: &configuration::Configuration, page: Option<i32>, limit: Option<i32>) -> Result<models::PaginatedDatasets, Error<DatasetsListError>> {
304    // add a prefix to parameters to efficiently prevent name collisions
305    let p_page = page;
306    let p_limit = limit;
307
308    let uri_str = format!("{}/api/public/v2/datasets", configuration.base_path);
309    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
310
311    if let Some(ref param_value) = p_page {
312        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
313    }
314    if let Some(ref param_value) = p_limit {
315        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
316    }
317    if let Some(ref user_agent) = configuration.user_agent {
318        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
319    }
320    if let Some(ref auth_conf) = configuration.basic_auth {
321        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
322    };
323
324    let req = req_builder.build()?;
325    let resp = configuration.client.execute(req).await?;
326
327    let status = resp.status();
328    let content_type = resp
329        .headers()
330        .get("content-type")
331        .and_then(|v| v.to_str().ok())
332        .unwrap_or("application/octet-stream");
333    let content_type = super::ContentType::from(content_type);
334
335    if !status.is_client_error() && !status.is_server_error() {
336        let content = resp.text().await?;
337        match content_type {
338            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
339            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PaginatedDatasets`"))),
340            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::PaginatedDatasets`")))),
341        }
342    } else {
343        let content = resp.text().await?;
344        let entity: Option<DatasetsListError> = serde_json::from_str(&content).ok();
345        Err(Error::ResponseError(ResponseContent { status, content, entity }))
346    }
347}
348