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
64pub async fn models_create(
66 configuration: &configuration::Configuration,
67 create_model_request: models::CreateModelRequest,
68) -> Result<models::Model, Error<ModelsCreateError>> {
69 let p_body_create_model_request = create_model_request;
71
72 let uri_str = format!("{}/api/public/models", configuration.base_path);
73 let mut req_builder = configuration
74 .client
75 .request(reqwest::Method::POST, &uri_str);
76
77 if let Some(ref user_agent) = configuration.user_agent {
78 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
79 }
80 if let Some(ref auth_conf) = configuration.basic_auth {
81 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
82 };
83 req_builder = req_builder.json(&p_body_create_model_request);
84
85 let req = req_builder.build()?;
86 let resp = configuration.client.execute(req).await?;
87
88 let status = resp.status();
89 let content_type = resp
90 .headers()
91 .get("content-type")
92 .and_then(|v| v.to_str().ok())
93 .unwrap_or("application/octet-stream");
94 let content_type = super::ContentType::from(content_type);
95
96 if !status.is_client_error() && !status.is_server_error() {
97 let content = resp.text().await?;
98 match content_type {
99 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
100 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Model`"))),
101 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`")))),
102 }
103 } else {
104 let content = resp.text().await?;
105 let entity: Option<ModelsCreateError> = serde_json::from_str(&content).ok();
106 Err(Error::ResponseError(ResponseContent {
107 status,
108 content,
109 entity,
110 }))
111 }
112}
113
114pub async fn models_delete(
116 configuration: &configuration::Configuration,
117 id: &str,
118) -> Result<(), Error<ModelsDeleteError>> {
119 let p_path_id = id;
121
122 let uri_str = format!(
123 "{}/api/public/models/{id}",
124 configuration.base_path,
125 id = crate::apis::urlencode(p_path_id)
126 );
127 let mut req_builder = configuration
128 .client
129 .request(reqwest::Method::DELETE, &uri_str);
130
131 if let Some(ref user_agent) = configuration.user_agent {
132 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
133 }
134 if let Some(ref auth_conf) = configuration.basic_auth {
135 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
136 };
137
138 let req = req_builder.build()?;
139 let resp = configuration.client.execute(req).await?;
140
141 let status = resp.status();
142
143 if !status.is_client_error() && !status.is_server_error() {
144 Ok(())
145 } else {
146 let content = resp.text().await?;
147 let entity: Option<ModelsDeleteError> = serde_json::from_str(&content).ok();
148 Err(Error::ResponseError(ResponseContent {
149 status,
150 content,
151 entity,
152 }))
153 }
154}
155
156pub async fn models_get(
158 configuration: &configuration::Configuration,
159 id: &str,
160) -> Result<models::Model, Error<ModelsGetError>> {
161 let p_path_id = id;
163
164 let uri_str = format!(
165 "{}/api/public/models/{id}",
166 configuration.base_path,
167 id = crate::apis::urlencode(p_path_id)
168 );
169 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
170
171 if let Some(ref user_agent) = configuration.user_agent {
172 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
173 }
174 if let Some(ref auth_conf) = configuration.basic_auth {
175 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
176 };
177
178 let req = req_builder.build()?;
179 let resp = configuration.client.execute(req).await?;
180
181 let status = resp.status();
182 let content_type = resp
183 .headers()
184 .get("content-type")
185 .and_then(|v| v.to_str().ok())
186 .unwrap_or("application/octet-stream");
187 let content_type = super::ContentType::from(content_type);
188
189 if !status.is_client_error() && !status.is_server_error() {
190 let content = resp.text().await?;
191 match content_type {
192 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
193 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Model`"))),
194 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`")))),
195 }
196 } else {
197 let content = resp.text().await?;
198 let entity: Option<ModelsGetError> = serde_json::from_str(&content).ok();
199 Err(Error::ResponseError(ResponseContent {
200 status,
201 content,
202 entity,
203 }))
204 }
205}
206
207pub async fn models_list(
209 configuration: &configuration::Configuration,
210 page: Option<i32>,
211 limit: Option<i32>,
212) -> Result<models::PaginatedModels, Error<ModelsListError>> {
213 let p_query_page = page;
215 let p_query_limit = limit;
216
217 let uri_str = format!("{}/api/public/models", configuration.base_path);
218 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
219
220 if let Some(ref param_value) = p_query_page {
221 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
222 }
223 if let Some(ref param_value) = p_query_limit {
224 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
225 }
226 if let Some(ref user_agent) = configuration.user_agent {
227 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
228 }
229 if let Some(ref auth_conf) = configuration.basic_auth {
230 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
231 };
232
233 let req = req_builder.build()?;
234 let resp = configuration.client.execute(req).await?;
235
236 let status = resp.status();
237 let content_type = resp
238 .headers()
239 .get("content-type")
240 .and_then(|v| v.to_str().ok())
241 .unwrap_or("application/octet-stream");
242 let content_type = super::ContentType::from(content_type);
243
244 if !status.is_client_error() && !status.is_server_error() {
245 let content = resp.text().await?;
246 match content_type {
247 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
248 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PaginatedModels`"))),
249 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`")))),
250 }
251 } else {
252 let content = resp.text().await?;
253 let entity: Option<ModelsListError> = serde_json::from_str(&content).ok();
254 Err(Error::ResponseError(ResponseContent {
255 status,
256 content,
257 entity,
258 }))
259 }
260}