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