async_openai/evals/
evals_.rs

1use crate::{
2    config::Config,
3    error::OpenAIError,
4    types::evals::{CreateEvalRequest, DeleteEvalResponse, Eval, EvalList, UpdateEvalRequest},
5    Client, EvalRuns, RequestOptions,
6};
7
8/// Create, manage, and run evals in the OpenAI platform. Related guide:
9/// [Evals](https://platform.openai.com/docs/guides/evals)
10pub struct Evals<'c, C: Config> {
11    client: &'c Client<C>,
12    pub(crate) request_options: RequestOptions,
13}
14
15impl<'c, C: Config> Evals<'c, C> {
16    pub fn new(client: &'c Client<C>) -> Self {
17        Self {
18            client,
19            request_options: RequestOptions::new(),
20        }
21    }
22
23    /// [EvalRuns] API group
24    pub fn runs(&self, eval_id: &str) -> EvalRuns<'_, C> {
25        EvalRuns::new(self.client, eval_id)
26    }
27
28    /// List evaluations for a project.
29    #[crate::byot(R = serde::de::DeserializeOwned)]
30    pub async fn list(&self) -> Result<EvalList, OpenAIError> {
31        self.client.get("/evals", &self.request_options).await
32    }
33
34    /// Create the structure of an evaluation that can be used to test a model's performance.
35    /// An evaluation is a set of testing criteria and the config for a data source, which dictates
36    /// the schema of the data used in the evaluation. After creating an evaluation, you can run it
37    /// on different models and model parameters. We support several types of graders and
38    /// datasources. For more information, see the [Evals guide](https://platform.openai.com/docs/guides/evals).
39    #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
40    pub async fn create(&self, request: CreateEvalRequest) -> Result<Eval, OpenAIError> {
41        self.client
42            .post("/evals", request, &self.request_options)
43            .await
44    }
45
46    /// Get an evaluation by ID.
47    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
48    pub async fn retrieve(&self, eval_id: &str) -> Result<Eval, OpenAIError> {
49        self.client
50            .get(&format!("/evals/{eval_id}"), &self.request_options)
51            .await
52    }
53
54    /// Update certain properties of an evaluation.
55    #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
56    pub async fn update(
57        &self,
58        eval_id: &str,
59        request: UpdateEvalRequest,
60    ) -> Result<Eval, OpenAIError> {
61        self.client
62            .post(&format!("/evals/{eval_id}"), request, &self.request_options)
63            .await
64    }
65
66    /// Delete an evaluation.
67    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
68    pub async fn delete(&self, eval_id: &str) -> Result<DeleteEvalResponse, OpenAIError> {
69        self.client
70            .delete(&format!("/evals/{eval_id}"), &self.request_options)
71            .await
72    }
73}