Skip to main content

langfuse_client_base/apis/
unstable_evaluators_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
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 [`unstable_evaluators_create`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum UnstableEvaluatorsCreateError {
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    Status409(models::UnstablePublicApiError),
26    Status422(models::UnstablePublicApiError),
27    Status429(models::UnstablePublicApiError),
28    Status500(models::UnstablePublicApiError),
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`unstable_evaluators_get`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum UnstableEvaluatorsGetError {
36    Status400(serde_json::Value),
37    Status401(serde_json::Value),
38    Status403(serde_json::Value),
39    Status404(serde_json::Value),
40    Status405(serde_json::Value),
41    Status429(models::UnstablePublicApiError),
42    Status500(models::UnstablePublicApiError),
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`unstable_evaluators_list`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum UnstableEvaluatorsListError {
50    Status400(serde_json::Value),
51    Status401(serde_json::Value),
52    Status403(serde_json::Value),
53    Status404(serde_json::Value),
54    Status405(serde_json::Value),
55    Status429(models::UnstablePublicApiError),
56    Status500(models::UnstablePublicApiError),
57    UnknownValue(serde_json::Value),
58}
59
60/// Create an evaluator in the authenticated project.  Use evaluators to define **how** Langfuse should score data: the prompt, the expected structured output, and the optional model configuration.  Naming behavior: - If this is a new evaluator name in your project, Langfuse creates version `1`. - If the name already exists in your project, Langfuse creates the next version and returns it. - When a new project version is created, existing evaluation rules in that project automatically move to the newest version for that evaluator name.  Recommended workflow: 1. Create the evaluator. 2. Read the returned `variables` array. 3. Read the returned `outputDefinition.dataType` so the client knows whether future scores will be numeric, boolean, or categorical. 4. Create one or more evaluation rules that reference the returned evaluator family using `name` and `scope`.  Recovery guidance: - `422` with `code=evaluator_preflight_failed`: the evaluator cannot run with the resolved model configuration. Add a valid explicit `modelConfig`, or configure the project's default evaluation model, then retry the same request. - `400` with `code=invalid_body`: the request shape is malformed. Use the structured `details.issues` array to fix the specific fields and retry. - `400` with `code=invalid_body` on `outputDefinition`: send `dataType`, `reasoning.description`, and `score.description`. Do not send `version`; it is not part of the public request shape.  Unstable API note: - This surface may evolve while the underlying evaluation data model is being redesigned.
61#[bon::builder]
62pub async fn unstable_evaluators_create(
63    configuration: &configuration::Configuration,
64    unstable_create_evaluator_request: models::UnstableCreateEvaluatorRequest,
65) -> Result<models::UnstableEvaluator, Error<UnstableEvaluatorsCreateError>> {
66    // add a prefix to parameters to efficiently prevent name collisions
67    let p_body_unstable_create_evaluator_request = unstable_create_evaluator_request;
68
69    let uri_str = format!("{}/api/public/unstable/evaluators", configuration.base_path);
70    let mut req_builder = configuration
71        .client
72        .request(reqwest::Method::POST, &uri_str);
73
74    if let Some(ref user_agent) = configuration.user_agent {
75        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
76    }
77    if let Some(ref auth_conf) = configuration.basic_auth {
78        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
79    };
80    req_builder = req_builder.json(&p_body_unstable_create_evaluator_request);
81
82    let req = req_builder.build()?;
83    let resp = configuration.client.execute(req).await?;
84
85    let status = resp.status();
86    let content_type = resp
87        .headers()
88        .get("content-type")
89        .and_then(|v| v.to_str().ok())
90        .unwrap_or("application/octet-stream");
91    let content_type = super::ContentType::from(content_type);
92
93    if !status.is_client_error() && !status.is_server_error() {
94        let content = resp.text().await?;
95        match content_type {
96            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
97            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UnstableEvaluator`"))),
98            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::UnstableEvaluator`")))),
99        }
100    } else {
101        let content = resp.text().await?;
102        let entity: Option<UnstableEvaluatorsCreateError> = serde_json::from_str(&content).ok();
103        Err(Error::ResponseError(ResponseContent {
104            status,
105            content,
106            entity,
107        }))
108    }
109}
110
111/// Get one evaluator by `id`.  Use this endpoint when you want the prompt, output definition, model configuration, and derived variables for the evaluator you plan to use in an evaluation rule.
112#[bon::builder]
113pub async fn unstable_evaluators_get(
114    configuration: &configuration::Configuration,
115    evaluator_id: &str,
116) -> Result<models::UnstableEvaluator, Error<UnstableEvaluatorsGetError>> {
117    // add a prefix to parameters to efficiently prevent name collisions
118    let p_path_evaluator_id = evaluator_id;
119
120    let uri_str = format!(
121        "{}/api/public/unstable/evaluators/{evaluatorId}",
122        configuration.base_path,
123        evaluatorId = crate::apis::urlencode(p_path_evaluator_id)
124    );
125    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
126
127    if let Some(ref user_agent) = configuration.user_agent {
128        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
129    }
130    if let Some(ref auth_conf) = configuration.basic_auth {
131        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
132    };
133
134    let req = req_builder.build()?;
135    let resp = configuration.client.execute(req).await?;
136
137    let status = resp.status();
138    let content_type = resp
139        .headers()
140        .get("content-type")
141        .and_then(|v| v.to_str().ok())
142        .unwrap_or("application/octet-stream");
143    let content_type = super::ContentType::from(content_type);
144
145    if !status.is_client_error() && !status.is_server_error() {
146        let content = resp.text().await?;
147        match content_type {
148            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
149            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UnstableEvaluator`"))),
150            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::UnstableEvaluator`")))),
151        }
152    } else {
153        let content = resp.text().await?;
154        let entity: Option<UnstableEvaluatorsGetError> = serde_json::from_str(&content).ok();
155        Err(Error::ResponseError(ResponseContent {
156            status,
157            content,
158            entity,
159        }))
160    }
161}
162
163/// List the evaluators available to the authenticated project.  Important behavior: - This endpoint returns the latest version of each available evaluator. - Results can include evaluators from your project and Langfuse-managed evaluators. - If the same evaluator name exists in both places, both are returned as separate items with different `scope` values.
164#[bon::builder]
165pub async fn unstable_evaluators_list(
166    configuration: &configuration::Configuration,
167    page: Option<i32>,
168    limit: Option<i32>,
169) -> Result<models::UnstableEvaluators, Error<UnstableEvaluatorsListError>> {
170    // add a prefix to parameters to efficiently prevent name collisions
171    let p_query_page = page;
172    let p_query_limit = limit;
173
174    let uri_str = format!("{}/api/public/unstable/evaluators", configuration.base_path);
175    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
176
177    if let Some(ref param_value) = p_query_page {
178        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
179    }
180    if let Some(ref param_value) = p_query_limit {
181        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
182    }
183    if let Some(ref user_agent) = configuration.user_agent {
184        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
185    }
186    if let Some(ref auth_conf) = configuration.basic_auth {
187        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
188    };
189
190    let req = req_builder.build()?;
191    let resp = configuration.client.execute(req).await?;
192
193    let status = resp.status();
194    let content_type = resp
195        .headers()
196        .get("content-type")
197        .and_then(|v| v.to_str().ok())
198        .unwrap_or("application/octet-stream");
199    let content_type = super::ContentType::from(content_type);
200
201    if !status.is_client_error() && !status.is_server_error() {
202        let content = resp.text().await?;
203        match content_type {
204            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
205            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UnstableEvaluators`"))),
206            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::UnstableEvaluators`")))),
207        }
208    } else {
209        let content = resp.text().await?;
210        let entity: Option<UnstableEvaluatorsListError> = serde_json::from_str(&content).ok();
211        Err(Error::ResponseError(ResponseContent {
212            status,
213            content,
214            entity,
215        }))
216    }
217}