/*
* langfuse
*
* ## 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
*
* The version of the OpenAPI document:
*
* Generated by: https://openapi-generator.tech
*/
use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};
/// struct for typed errors of method [`score_create`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ScoreCreateError {
Status400(serde_json::Value),
Status401(serde_json::Value),
Status403(serde_json::Value),
Status404(serde_json::Value),
Status405(serde_json::Value),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`score_delete`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ScoreDeleteError {
Status400(serde_json::Value),
Status401(serde_json::Value),
Status403(serde_json::Value),
Status404(serde_json::Value),
Status405(serde_json::Value),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`score_get`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ScoreGetError {
Status400(serde_json::Value),
Status401(serde_json::Value),
Status403(serde_json::Value),
Status404(serde_json::Value),
Status405(serde_json::Value),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`score_get_by_id`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ScoreGetByIdError {
Status400(serde_json::Value),
Status401(serde_json::Value),
Status403(serde_json::Value),
Status404(serde_json::Value),
Status405(serde_json::Value),
UnknownValue(serde_json::Value),
}
/// Create a score
pub async fn score_create(configuration: &configuration::Configuration, create_score_request: models::CreateScoreRequest) -> Result<models::CreateScoreResponse, Error<ScoreCreateError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_create_score_request = create_score_request;
let uri_str = format!("{}/api/public/scores", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
req_builder = req_builder.json(&p_create_score_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateScoreResponse`"))),
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::CreateScoreResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ScoreCreateError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Delete a score
pub async fn score_delete(configuration: &configuration::Configuration, score_id: &str) -> Result<(), Error<ScoreDeleteError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_score_id = score_id;
let uri_str = format!("{}/api/public/scores/{scoreId}", configuration.base_path, scoreId=crate::apis::urlencode(p_score_id));
let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<ScoreDeleteError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Get a list of scores
pub async fn score_get(configuration: &configuration::Configuration, page: Option<i32>, limit: Option<i32>, user_id: Option<&str>, name: Option<&str>, from_timestamp: Option<String>, to_timestamp: Option<String>, environment: Option<Vec<String>>, source: Option<models::ScoreSource>, operator: Option<&str>, value: Option<f64>, score_ids: Option<&str>, config_id: Option<&str>, queue_id: Option<&str>, data_type: Option<models::ScoreDataType>, trace_tags: Option<Vec<String>>) -> Result<models::GetScoresResponse, Error<ScoreGetError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_page = page;
let p_limit = limit;
let p_user_id = user_id;
let p_name = name;
let p_from_timestamp = from_timestamp;
let p_to_timestamp = to_timestamp;
let p_environment = environment;
let p_source = source;
let p_operator = operator;
let p_value = value;
let p_score_ids = score_ids;
let p_config_id = config_id;
let p_queue_id = queue_id;
let p_data_type = data_type;
let p_trace_tags = trace_tags;
let uri_str = format!("{}/api/public/scores", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_page {
req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_user_id {
req_builder = req_builder.query(&[("userId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_name {
req_builder = req_builder.query(&[("name", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_from_timestamp {
req_builder = req_builder.query(&[("fromTimestamp", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_to_timestamp {
req_builder = req_builder.query(&[("toTimestamp", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_environment {
req_builder = match "multi" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("environment".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("environment", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
}
if let Some(ref param_value) = p_source {
req_builder = req_builder.query(&[("source", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_operator {
req_builder = req_builder.query(&[("operator", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_value {
req_builder = req_builder.query(&[("value", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_score_ids {
req_builder = req_builder.query(&[("scoreIds", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_config_id {
req_builder = req_builder.query(&[("configId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_queue_id {
req_builder = req_builder.query(&[("queueId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_data_type {
req_builder = req_builder.query(&[("dataType", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_trace_tags {
req_builder = match "multi" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("traceTags".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("traceTags", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetScoresResponse`"))),
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::GetScoresResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ScoreGetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Get a score
pub async fn score_get_by_id(configuration: &configuration::Configuration, score_id: &str) -> Result<models::Score, Error<ScoreGetByIdError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_score_id = score_id;
let uri_str = format!("{}/api/public/scores/{scoreId}", configuration.base_path, scoreId=crate::apis::urlencode(p_score_id));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Score`"))),
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::Score`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ScoreGetByIdError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}