async_openai/
eval_runs.rs

1use crate::{
2    config::Config,
3    error::OpenAIError,
4    eval_run_output_items::EvalRunOutputItems,
5    types::evals::{CreateEvalRunRequest, DeleteEvalRunResponse, EvalRun, EvalRunList},
6    Client, RequestOptions,
7};
8
9pub struct EvalRuns<'c, C: Config> {
10    client: &'c Client<C>,
11    pub eval_id: String,
12    pub(crate) request_options: RequestOptions,
13}
14
15impl<'c, C: Config> EvalRuns<'c, C> {
16    pub fn new(client: &'c Client<C>, eval_id: &str) -> Self {
17        Self {
18            client,
19            eval_id: eval_id.into(),
20            request_options: RequestOptions::new(),
21        }
22    }
23
24    /// [EvalRunOutputItems] API group
25    pub fn output_items(&self, run_id: &str) -> EvalRunOutputItems<'_, C> {
26        EvalRunOutputItems::new(self.client, &self.eval_id, run_id)
27    }
28
29    /// Get a list of runs for an evaluation.
30    #[crate::byot(R = serde::de::DeserializeOwned)]
31    pub async fn list(&self) -> Result<EvalRunList, OpenAIError> {
32        self.client
33            .get(
34                &format!("/evals/{}/runs", self.eval_id),
35                &self.request_options,
36            )
37            .await
38    }
39
40    /// Kicks off a new run for a given evaluation.
41    #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
42    pub async fn create(&self, request: CreateEvalRunRequest) -> Result<EvalRun, OpenAIError> {
43        self.client
44            .post(
45                &format!("/evals/{}/runs", self.eval_id),
46                request,
47                &self.request_options,
48            )
49            .await
50    }
51
52    /// Get an evaluation run by ID.
53    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
54    pub async fn retrieve(&self, run_id: &str) -> Result<EvalRun, OpenAIError> {
55        self.client
56            .get(
57                &format!("/evals/{}/runs/{}", self.eval_id, run_id),
58                &self.request_options,
59            )
60            .await
61    }
62
63    /// Cancel an ongoing evaluation run.
64    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
65    pub async fn cancel(&self, run_id: &str) -> Result<EvalRun, OpenAIError> {
66        self.client
67            .post(
68                &format!("/evals/{}/runs/{}", self.eval_id, run_id),
69                serde_json::json!({}),
70                &self.request_options,
71            )
72            .await
73    }
74
75    /// Delete an eval run.
76    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
77    pub async fn delete(&self, run_id: &str) -> Result<DeleteEvalRunResponse, OpenAIError> {
78        self.client
79            .delete(
80                &format!("/evals/{}/runs/{}", self.eval_id, run_id),
81                &self.request_options,
82            )
83            .await
84    }
85}