langfuse_client_base/apis/
score_configs_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
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for typed errors of method [`score_configs_create`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum ScoreConfigsCreateError {
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/// struct for typed errors of method [`score_configs_get`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum ScoreConfigsGetError {
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/// struct for typed errors of method [`score_configs_get_by_id`]
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum ScoreConfigsGetByIdError {
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/// struct for typed errors of method [`score_configs_update`]
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum ScoreConfigsUpdateError {
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/// Create a score configuration (config). Score configs are used to define the structure of scores
65#[bon::builder]
66pub async fn score_configs_create(
67    configuration: &configuration::Configuration,
68    create_score_config_request: models::CreateScoreConfigRequest,
69) -> Result<models::ScoreConfig, Error<ScoreConfigsCreateError>> {
70    // add a prefix to parameters to efficiently prevent name collisions
71    let p_body_create_score_config_request = create_score_config_request;
72
73    let uri_str = format!("{}/api/public/score-configs", 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_score_config_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::ScoreConfig`"))),
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::ScoreConfig`")))),
103        }
104    } else {
105        let content = resp.text().await?;
106        let entity: Option<ScoreConfigsCreateError> = serde_json::from_str(&content).ok();
107        Err(Error::ResponseError(ResponseContent {
108            status,
109            content,
110            entity,
111        }))
112    }
113}
114
115/// Get all score configs
116#[bon::builder]
117pub async fn score_configs_get(
118    configuration: &configuration::Configuration,
119    page: Option<i32>,
120    limit: Option<i32>,
121) -> Result<models::ScoreConfigs, Error<ScoreConfigsGetError>> {
122    // add a prefix to parameters to efficiently prevent name collisions
123    let p_query_page = page;
124    let p_query_limit = limit;
125
126    let uri_str = format!("{}/api/public/score-configs", configuration.base_path);
127    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
128
129    if let Some(ref param_value) = p_query_page {
130        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
131    }
132    if let Some(ref param_value) = p_query_limit {
133        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
134    }
135    if let Some(ref user_agent) = configuration.user_agent {
136        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
137    }
138    if let Some(ref auth_conf) = configuration.basic_auth {
139        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
140    };
141
142    let req = req_builder.build()?;
143    let resp = configuration.client.execute(req).await?;
144
145    let status = resp.status();
146    let content_type = resp
147        .headers()
148        .get("content-type")
149        .and_then(|v| v.to_str().ok())
150        .unwrap_or("application/octet-stream");
151    let content_type = super::ContentType::from(content_type);
152
153    if !status.is_client_error() && !status.is_server_error() {
154        let content = resp.text().await?;
155        match content_type {
156            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
157            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ScoreConfigs`"))),
158            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::ScoreConfigs`")))),
159        }
160    } else {
161        let content = resp.text().await?;
162        let entity: Option<ScoreConfigsGetError> = serde_json::from_str(&content).ok();
163        Err(Error::ResponseError(ResponseContent {
164            status,
165            content,
166            entity,
167        }))
168    }
169}
170
171/// Get a score config
172#[bon::builder]
173pub async fn score_configs_get_by_id(
174    configuration: &configuration::Configuration,
175    config_id: &str,
176) -> Result<models::ScoreConfig, Error<ScoreConfigsGetByIdError>> {
177    // add a prefix to parameters to efficiently prevent name collisions
178    let p_path_config_id = config_id;
179
180    let uri_str = format!(
181        "{}/api/public/score-configs/{configId}",
182        configuration.base_path,
183        configId = crate::apis::urlencode(p_path_config_id)
184    );
185    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
186
187    if let Some(ref user_agent) = configuration.user_agent {
188        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
189    }
190    if let Some(ref auth_conf) = configuration.basic_auth {
191        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
192    };
193
194    let req = req_builder.build()?;
195    let resp = configuration.client.execute(req).await?;
196
197    let status = resp.status();
198    let content_type = resp
199        .headers()
200        .get("content-type")
201        .and_then(|v| v.to_str().ok())
202        .unwrap_or("application/octet-stream");
203    let content_type = super::ContentType::from(content_type);
204
205    if !status.is_client_error() && !status.is_server_error() {
206        let content = resp.text().await?;
207        match content_type {
208            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
209            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ScoreConfig`"))),
210            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::ScoreConfig`")))),
211        }
212    } else {
213        let content = resp.text().await?;
214        let entity: Option<ScoreConfigsGetByIdError> = serde_json::from_str(&content).ok();
215        Err(Error::ResponseError(ResponseContent {
216            status,
217            content,
218            entity,
219        }))
220    }
221}
222
223/// Update a score config
224#[bon::builder]
225pub async fn score_configs_update(
226    configuration: &configuration::Configuration,
227    config_id: &str,
228    update_score_config_request: models::UpdateScoreConfigRequest,
229) -> Result<models::ScoreConfig, Error<ScoreConfigsUpdateError>> {
230    // add a prefix to parameters to efficiently prevent name collisions
231    let p_path_config_id = config_id;
232    let p_body_update_score_config_request = update_score_config_request;
233
234    let uri_str = format!(
235        "{}/api/public/score-configs/{configId}",
236        configuration.base_path,
237        configId = crate::apis::urlencode(p_path_config_id)
238    );
239    let mut req_builder = configuration
240        .client
241        .request(reqwest::Method::PATCH, &uri_str);
242
243    if let Some(ref user_agent) = configuration.user_agent {
244        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
245    }
246    if let Some(ref auth_conf) = configuration.basic_auth {
247        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
248    };
249    req_builder = req_builder.json(&p_body_update_score_config_request);
250
251    let req = req_builder.build()?;
252    let resp = configuration.client.execute(req).await?;
253
254    let status = resp.status();
255    let content_type = resp
256        .headers()
257        .get("content-type")
258        .and_then(|v| v.to_str().ok())
259        .unwrap_or("application/octet-stream");
260    let content_type = super::ContentType::from(content_type);
261
262    if !status.is_client_error() && !status.is_server_error() {
263        let content = resp.text().await?;
264        match content_type {
265            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
266            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ScoreConfig`"))),
267            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::ScoreConfig`")))),
268        }
269    } else {
270        let content = resp.text().await?;
271        let entity: Option<ScoreConfigsUpdateError> = serde_json::from_str(&content).ok();
272        Err(Error::ResponseError(ResponseContent {
273            status,
274            content,
275            entity,
276        }))
277    }
278}