langfuse_client/apis/
score_configs_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ScoreConfigsCreateError {
22 Status400(serde_json::Value),
23 Status401(serde_json::Value),
24 Status403(serde_json::Value),
25 Status404(serde_json::Value),
26 Status405(serde_json::Value),
27 UnknownValue(serde_json::Value),
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum ScoreConfigsGetError {
34 Status400(serde_json::Value),
35 Status401(serde_json::Value),
36 Status403(serde_json::Value),
37 Status404(serde_json::Value),
38 Status405(serde_json::Value),
39 UnknownValue(serde_json::Value),
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum ScoreConfigsGetByIdError {
46 Status400(serde_json::Value),
47 Status401(serde_json::Value),
48 Status403(serde_json::Value),
49 Status404(serde_json::Value),
50 Status405(serde_json::Value),
51 UnknownValue(serde_json::Value),
52}
53
54
55pub async fn score_configs_create(configuration: &configuration::Configuration, create_score_config_request: models::CreateScoreConfigRequest) -> Result<models::ScoreConfig, Error<ScoreConfigsCreateError>> {
57 let p_create_score_config_request = create_score_config_request;
59
60 let uri_str = format!("{}/api/public/score-configs", configuration.base_path);
61 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
62
63 if let Some(ref user_agent) = configuration.user_agent {
64 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
65 }
66 if let Some(ref auth_conf) = configuration.basic_auth {
67 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
68 };
69 req_builder = req_builder.json(&p_create_score_config_request);
70
71 let req = req_builder.build()?;
72 let resp = configuration.client.execute(req).await?;
73
74 let status = resp.status();
75 let content_type = resp
76 .headers()
77 .get("content-type")
78 .and_then(|v| v.to_str().ok())
79 .unwrap_or("application/octet-stream");
80 let content_type = super::ContentType::from(content_type);
81
82 if !status.is_client_error() && !status.is_server_error() {
83 let content = resp.text().await?;
84 match content_type {
85 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
86 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ScoreConfig`"))),
87 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`")))),
88 }
89 } else {
90 let content = resp.text().await?;
91 let entity: Option<ScoreConfigsCreateError> = serde_json::from_str(&content).ok();
92 Err(Error::ResponseError(ResponseContent { status, content, entity }))
93 }
94}
95
96pub async fn score_configs_get(configuration: &configuration::Configuration, page: Option<i32>, limit: Option<i32>) -> Result<models::ScoreConfigs, Error<ScoreConfigsGetError>> {
98 let p_page = page;
100 let p_limit = limit;
101
102 let uri_str = format!("{}/api/public/score-configs", configuration.base_path);
103 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
104
105 if let Some(ref param_value) = p_page {
106 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
107 }
108 if let Some(ref param_value) = p_limit {
109 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
110 }
111 if let Some(ref user_agent) = configuration.user_agent {
112 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
113 }
114 if let Some(ref auth_conf) = configuration.basic_auth {
115 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
116 };
117
118 let req = req_builder.build()?;
119 let resp = configuration.client.execute(req).await?;
120
121 let status = resp.status();
122 let content_type = resp
123 .headers()
124 .get("content-type")
125 .and_then(|v| v.to_str().ok())
126 .unwrap_or("application/octet-stream");
127 let content_type = super::ContentType::from(content_type);
128
129 if !status.is_client_error() && !status.is_server_error() {
130 let content = resp.text().await?;
131 match content_type {
132 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
133 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ScoreConfigs`"))),
134 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`")))),
135 }
136 } else {
137 let content = resp.text().await?;
138 let entity: Option<ScoreConfigsGetError> = serde_json::from_str(&content).ok();
139 Err(Error::ResponseError(ResponseContent { status, content, entity }))
140 }
141}
142
143pub async fn score_configs_get_by_id(configuration: &configuration::Configuration, config_id: &str) -> Result<models::ScoreConfig, Error<ScoreConfigsGetByIdError>> {
145 let p_config_id = config_id;
147
148 let uri_str = format!("{}/api/public/score-configs/{configId}", configuration.base_path, configId=crate::apis::urlencode(p_config_id));
149 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
150
151 if let Some(ref user_agent) = configuration.user_agent {
152 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
153 }
154 if let Some(ref auth_conf) = configuration.basic_auth {
155 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
156 };
157
158 let req = req_builder.build()?;
159 let resp = configuration.client.execute(req).await?;
160
161 let status = resp.status();
162 let content_type = resp
163 .headers()
164 .get("content-type")
165 .and_then(|v| v.to_str().ok())
166 .unwrap_or("application/octet-stream");
167 let content_type = super::ContentType::from(content_type);
168
169 if !status.is_client_error() && !status.is_server_error() {
170 let content = resp.text().await?;
171 match content_type {
172 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
173 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ScoreConfig`"))),
174 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`")))),
175 }
176 } else {
177 let content = resp.text().await?;
178 let entity: Option<ScoreConfigsGetByIdError> = serde_json::from_str(&content).ok();
179 Err(Error::ResponseError(ResponseContent { status, content, entity }))
180 }
181}
182