langfuse_client_base/apis/
models_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 ModelsCreateError {
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 ModelsDeleteError {
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 ModelsGetError {
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 ModelsListError {
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#[derive(Debug, Clone, Serialize, Deserialize)]
66#[serde(untagged)]
67pub enum ModelsUpsertError {
68 Status400(serde_json::Value),
69 Status401(serde_json::Value),
70 Status403(serde_json::Value),
71 Status404(serde_json::Value),
72 Status405(serde_json::Value),
73 UnknownValue(serde_json::Value),
74}
75
76#[bon::builder]
78pub async fn models_create(
79 configuration: &configuration::Configuration,
80 create_model_request: models::CreateModelRequest,
81) -> Result<models::Model, Error<ModelsCreateError>> {
82 let p_body_create_model_request = create_model_request;
84
85 let uri_str = format!("{}/api/public/models", configuration.base_path);
86 let mut req_builder = configuration
87 .client
88 .request(reqwest::Method::POST, &uri_str);
89
90 if let Some(ref user_agent) = configuration.user_agent {
91 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
92 }
93 if let Some(ref auth_conf) = configuration.basic_auth {
94 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
95 };
96 req_builder = req_builder.json(&p_body_create_model_request);
97
98 let req = req_builder.build()?;
99 let resp = configuration.client.execute(req).await?;
100
101 let status = resp.status();
102 let content_type = resp
103 .headers()
104 .get("content-type")
105 .and_then(|v| v.to_str().ok())
106 .unwrap_or("application/octet-stream");
107 let content_type = super::ContentType::from(content_type);
108
109 if !status.is_client_error() && !status.is_server_error() {
110 let content = resp.text().await?;
111 match content_type {
112 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
113 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Model`"))),
114 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::Model`")))),
115 }
116 } else {
117 let content = resp.text().await?;
118 let entity: Option<ModelsCreateError> = serde_json::from_str(&content).ok();
119 Err(Error::ResponseError(ResponseContent {
120 status,
121 content,
122 entity,
123 }))
124 }
125}
126
127#[bon::builder]
129pub async fn models_delete(
130 configuration: &configuration::Configuration,
131 id: &str,
132) -> Result<(), Error<ModelsDeleteError>> {
133 let p_path_id = id;
135
136 let uri_str = format!(
137 "{}/api/public/models/{id}",
138 configuration.base_path,
139 id = crate::apis::urlencode(p_path_id)
140 );
141 let mut req_builder = configuration
142 .client
143 .request(reqwest::Method::DELETE, &uri_str);
144
145 if let Some(ref user_agent) = configuration.user_agent {
146 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
147 }
148 if let Some(ref auth_conf) = configuration.basic_auth {
149 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
150 };
151
152 let req = req_builder.build()?;
153 let resp = configuration.client.execute(req).await?;
154
155 let status = resp.status();
156
157 if !status.is_client_error() && !status.is_server_error() {
158 Ok(())
159 } else {
160 let content = resp.text().await?;
161 let entity: Option<ModelsDeleteError> = serde_json::from_str(&content).ok();
162 Err(Error::ResponseError(ResponseContent {
163 status,
164 content,
165 entity,
166 }))
167 }
168}
169
170#[bon::builder]
172pub async fn models_get(
173 configuration: &configuration::Configuration,
174 id: &str,
175) -> Result<models::Model, Error<ModelsGetError>> {
176 let p_path_id = id;
178
179 let uri_str = format!(
180 "{}/api/public/models/{id}",
181 configuration.base_path,
182 id = crate::apis::urlencode(p_path_id)
183 );
184 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
185
186 if let Some(ref user_agent) = configuration.user_agent {
187 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
188 }
189 if let Some(ref auth_conf) = configuration.basic_auth {
190 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
191 };
192
193 let req = req_builder.build()?;
194 let resp = configuration.client.execute(req).await?;
195
196 let status = resp.status();
197 let content_type = resp
198 .headers()
199 .get("content-type")
200 .and_then(|v| v.to_str().ok())
201 .unwrap_or("application/octet-stream");
202 let content_type = super::ContentType::from(content_type);
203
204 if !status.is_client_error() && !status.is_server_error() {
205 let content = resp.text().await?;
206 match content_type {
207 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
208 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Model`"))),
209 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::Model`")))),
210 }
211 } else {
212 let content = resp.text().await?;
213 let entity: Option<ModelsGetError> = serde_json::from_str(&content).ok();
214 Err(Error::ResponseError(ResponseContent {
215 status,
216 content,
217 entity,
218 }))
219 }
220}
221
222#[bon::builder]
224pub async fn models_list(
225 configuration: &configuration::Configuration,
226 page: Option<i32>,
227 limit: Option<i32>,
228) -> Result<models::PaginatedModels, Error<ModelsListError>> {
229 let p_query_page = page;
231 let p_query_limit = limit;
232
233 let uri_str = format!("{}/api/public/models", configuration.base_path);
234 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
235
236 if let Some(ref param_value) = p_query_page {
237 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
238 }
239 if let Some(ref param_value) = p_query_limit {
240 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
241 }
242 if let Some(ref user_agent) = configuration.user_agent {
243 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
244 }
245 if let Some(ref auth_conf) = configuration.basic_auth {
246 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
247 };
248
249 let req = req_builder.build()?;
250 let resp = configuration.client.execute(req).await?;
251
252 let status = resp.status();
253 let content_type = resp
254 .headers()
255 .get("content-type")
256 .and_then(|v| v.to_str().ok())
257 .unwrap_or("application/octet-stream");
258 let content_type = super::ContentType::from(content_type);
259
260 if !status.is_client_error() && !status.is_server_error() {
261 let content = resp.text().await?;
262 match content_type {
263 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
264 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PaginatedModels`"))),
265 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::PaginatedModels`")))),
266 }
267 } else {
268 let content = resp.text().await?;
269 let entity: Option<ModelsListError> = serde_json::from_str(&content).ok();
270 Err(Error::ResponseError(ResponseContent {
271 status,
272 content,
273 entity,
274 }))
275 }
276}
277
278#[bon::builder]
280pub async fn models_upsert(
281 configuration: &configuration::Configuration,
282 id: &str,
283 create_model_request: models::CreateModelRequest,
284) -> Result<models::Model, Error<ModelsUpsertError>> {
285 let p_path_id = id;
287 let p_body_create_model_request = create_model_request;
288
289 let uri_str = format!(
290 "{}/api/public/models/{id}",
291 configuration.base_path,
292 id = crate::apis::urlencode(p_path_id)
293 );
294 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
295
296 if let Some(ref user_agent) = configuration.user_agent {
297 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
298 }
299 if let Some(ref auth_conf) = configuration.basic_auth {
300 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
301 };
302 req_builder = req_builder.json(&p_body_create_model_request);
303
304 let req = req_builder.build()?;
305 let resp = configuration.client.execute(req).await?;
306
307 let status = resp.status();
308 let content_type = resp
309 .headers()
310 .get("content-type")
311 .and_then(|v| v.to_str().ok())
312 .unwrap_or("application/octet-stream");
313 let content_type = super::ContentType::from(content_type);
314
315 if !status.is_client_error() && !status.is_server_error() {
316 let content = resp.text().await?;
317 match content_type {
318 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
319 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Model`"))),
320 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::Model`")))),
321 }
322 } else {
323 let content = resp.text().await?;
324 let entity: Option<ModelsUpsertError> = serde_json::from_str(&content).ok();
325 Err(Error::ResponseError(ResponseContent {
326 status,
327 content,
328 entity,
329 }))
330 }
331}