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