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#[bon::builder]
66pub async fn models_create(
67 configuration: &configuration::Configuration,
68 create_model_request: models::CreateModelRequest,
69) -> Result<models::Model, Error<ModelsCreateError>> {
70 let p_body_create_model_request = create_model_request;
72
73 let uri_str = format!("{}/api/public/models", 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_model_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::Model`"))),
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::Model`")))),
103 }
104 } else {
105 let content = resp.text().await?;
106 let entity: Option<ModelsCreateError> = 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 models_delete(
118 configuration: &configuration::Configuration,
119 id: &str,
120) -> Result<(), Error<ModelsDeleteError>> {
121 let p_path_id = id;
123
124 let uri_str = format!(
125 "{}/api/public/models/{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
145 if !status.is_client_error() && !status.is_server_error() {
146 Ok(())
147 } else {
148 let content = resp.text().await?;
149 let entity: Option<ModelsDeleteError> = serde_json::from_str(&content).ok();
150 Err(Error::ResponseError(ResponseContent {
151 status,
152 content,
153 entity,
154 }))
155 }
156}
157
158#[bon::builder]
160pub async fn models_get(
161 configuration: &configuration::Configuration,
162 id: &str,
163) -> Result<models::Model, Error<ModelsGetError>> {
164 let p_path_id = id;
166
167 let uri_str = format!(
168 "{}/api/public/models/{id}",
169 configuration.base_path,
170 id = crate::apis::urlencode(p_path_id)
171 );
172 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
173
174 if let Some(ref user_agent) = configuration.user_agent {
175 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
176 }
177 if let Some(ref auth_conf) = configuration.basic_auth {
178 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
179 };
180
181 let req = req_builder.build()?;
182 let resp = configuration.client.execute(req).await?;
183
184 let status = resp.status();
185 let content_type = resp
186 .headers()
187 .get("content-type")
188 .and_then(|v| v.to_str().ok())
189 .unwrap_or("application/octet-stream");
190 let content_type = super::ContentType::from(content_type);
191
192 if !status.is_client_error() && !status.is_server_error() {
193 let content = resp.text().await?;
194 match content_type {
195 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
196 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Model`"))),
197 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`")))),
198 }
199 } else {
200 let content = resp.text().await?;
201 let entity: Option<ModelsGetError> = serde_json::from_str(&content).ok();
202 Err(Error::ResponseError(ResponseContent {
203 status,
204 content,
205 entity,
206 }))
207 }
208}
209
210#[bon::builder]
212pub async fn models_list(
213 configuration: &configuration::Configuration,
214 page: Option<i32>,
215 limit: Option<i32>,
216) -> Result<models::PaginatedModels, Error<ModelsListError>> {
217 let p_query_page = page;
219 let p_query_limit = limit;
220
221 let uri_str = format!("{}/api/public/models", configuration.base_path);
222 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
223
224 if let Some(ref param_value) = p_query_page {
225 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
226 }
227 if let Some(ref param_value) = p_query_limit {
228 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
229 }
230 if let Some(ref user_agent) = configuration.user_agent {
231 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
232 }
233 if let Some(ref auth_conf) = configuration.basic_auth {
234 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
235 };
236
237 let req = req_builder.build()?;
238 let resp = configuration.client.execute(req).await?;
239
240 let status = resp.status();
241 let content_type = resp
242 .headers()
243 .get("content-type")
244 .and_then(|v| v.to_str().ok())
245 .unwrap_or("application/octet-stream");
246 let content_type = super::ContentType::from(content_type);
247
248 if !status.is_client_error() && !status.is_server_error() {
249 let content = resp.text().await?;
250 match content_type {
251 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
252 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PaginatedModels`"))),
253 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`")))),
254 }
255 } else {
256 let content = resp.text().await?;
257 let entity: Option<ModelsListError> = serde_json::from_str(&content).ok();
258 Err(Error::ResponseError(ResponseContent {
259 status,
260 content,
261 entity,
262 }))
263 }
264}