langfuse_rs/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, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{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/// Create a score configuration (config). Score configs are used to define the structure of scores
53pub async fn score_configs_create(
54	configuration: &configuration::Configuration,
55	create_score_config_request: models::CreateScoreConfigRequest,
56) -> Result<models::ScoreConfig, Error<ScoreConfigsCreateError>> {
57	// add a prefix to parameters to efficiently prevent name collisions
58	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
76	if !status.is_client_error() && !status.is_server_error() {
77		let content = resp.text().await?;
78		serde_json::from_str(&content).map_err(Error::from)
79	} else {
80		let content = resp.text().await?;
81		let entity: Option<ScoreConfigsCreateError> = serde_json::from_str(&content).ok();
82		Err(Error::ResponseError(ResponseContent { status, content, entity }))
83	}
84}
85
86/// Get all score configs
87pub async fn score_configs_get(
88	configuration: &configuration::Configuration,
89	page: Option<i32>,
90	limit: Option<i32>,
91) -> Result<models::ScoreConfigs, Error<ScoreConfigsGetError>> {
92	// add a prefix to parameters to efficiently prevent name collisions
93	let p_page = page;
94	let p_limit = limit;
95
96	let uri_str = format!("{}/api/public/score-configs", configuration.base_path);
97	let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
98
99	if let Some(ref param_value) = p_page {
100		req_builder = req_builder.query(&[("page", &param_value.to_string())]);
101	}
102	if let Some(ref param_value) = p_limit {
103		req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
104	}
105	if let Some(ref user_agent) = configuration.user_agent {
106		req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
107	}
108	if let Some(ref auth_conf) = configuration.basic_auth {
109		req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
110	};
111
112	let req = req_builder.build()?;
113	let resp = configuration.client.execute(req).await?;
114
115	let status = resp.status();
116
117	if !status.is_client_error() && !status.is_server_error() {
118		let content = resp.text().await?;
119		serde_json::from_str(&content).map_err(Error::from)
120	} else {
121		let content = resp.text().await?;
122		let entity: Option<ScoreConfigsGetError> = serde_json::from_str(&content).ok();
123		Err(Error::ResponseError(ResponseContent { status, content, entity }))
124	}
125}
126
127/// Get a score config
128pub async fn score_configs_get_by_id(
129	configuration: &configuration::Configuration,
130	config_id: &str,
131) -> Result<models::ScoreConfig, Error<ScoreConfigsGetByIdError>> {
132	// add a prefix to parameters to efficiently prevent name collisions
133	let p_config_id = config_id;
134
135	let uri_str = format!(
136		"{}/api/public/score-configs/{configId}",
137		configuration.base_path,
138		configId = crate::apis::urlencode(p_config_id)
139	);
140	let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
141
142	if let Some(ref user_agent) = configuration.user_agent {
143		req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
144	}
145	if let Some(ref auth_conf) = configuration.basic_auth {
146		req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
147	};
148
149	let req = req_builder.build()?;
150	let resp = configuration.client.execute(req).await?;
151
152	let status = resp.status();
153
154	if !status.is_client_error() && !status.is_server_error() {
155		let content = resp.text().await?;
156		serde_json::from_str(&content).map_err(Error::from)
157	} else {
158		let content = resp.text().await?;
159		let entity: Option<ScoreConfigsGetByIdError> = serde_json::from_str(&content).ok();
160		Err(Error::ResponseError(ResponseContent { status, content, entity }))
161	}
162}