async_openai/
eval_runs.rs1use 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 pub fn output_items(&self, run_id: &str) -> EvalRunOutputItems<'_, C> {
26 EvalRunOutputItems::new(self.client, &self.eval_id, run_id)
27 }
28
29 #[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 #[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 #[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 #[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 #[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}