langfuse_client_base/apis/
dataset_items_api.rs1use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16#[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#[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#[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#[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#[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 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#[bon::builder]
117pub async fn dataset_items_delete(
118 configuration: &configuration::Configuration,
119 id: &str,
120) -> Result<models::DeleteDatasetItemResponse, Error<DatasetItemsDeleteError>> {
121 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#[bon::builder]
171pub async fn dataset_items_get(
172 configuration: &configuration::Configuration,
173 id: &str,
174) -> Result<models::DatasetItem, Error<DatasetItemsGetError>> {
175 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#[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 page: Option<i32>,
229 limit: Option<i32>,
230) -> Result<models::PaginatedDatasetItems, Error<DatasetItemsListError>> {
231 let p_query_dataset_name = dataset_name;
233 let p_query_source_trace_id = source_trace_id;
234 let p_query_source_observation_id = source_observation_id;
235 let p_query_page = page;
236 let p_query_limit = limit;
237
238 let uri_str = format!("{}/api/public/dataset-items", configuration.base_path);
239 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
240
241 if let Some(ref param_value) = p_query_dataset_name {
242 req_builder = req_builder.query(&[("datasetName", ¶m_value.to_string())]);
243 }
244 if let Some(ref param_value) = p_query_source_trace_id {
245 req_builder = req_builder.query(&[("sourceTraceId", ¶m_value.to_string())]);
246 }
247 if let Some(ref param_value) = p_query_source_observation_id {
248 req_builder = req_builder.query(&[("sourceObservationId", ¶m_value.to_string())]);
249 }
250 if let Some(ref param_value) = p_query_page {
251 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
252 }
253 if let Some(ref param_value) = p_query_limit {
254 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
255 }
256 if let Some(ref user_agent) = configuration.user_agent {
257 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
258 }
259 if let Some(ref auth_conf) = configuration.basic_auth {
260 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
261 };
262
263 let req = req_builder.build()?;
264 let resp = configuration.client.execute(req).await?;
265
266 let status = resp.status();
267 let content_type = resp
268 .headers()
269 .get("content-type")
270 .and_then(|v| v.to_str().ok())
271 .unwrap_or("application/octet-stream");
272 let content_type = super::ContentType::from(content_type);
273
274 if !status.is_client_error() && !status.is_server_error() {
275 let content = resp.text().await?;
276 match content_type {
277 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
278 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PaginatedDatasetItems`"))),
279 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`")))),
280 }
281 } else {
282 let content = resp.text().await?;
283 let entity: Option<DatasetItemsListError> = serde_json::from_str(&content).ok();
284 Err(Error::ResponseError(ResponseContent {
285 status,
286 content,
287 entity,
288 }))
289 }
290}