async_openai/evals/
evals_.rs1use crate::{
2 config::Config,
3 error::OpenAIError,
4 types::evals::{CreateEvalRequest, DeleteEvalResponse, Eval, EvalList, UpdateEvalRequest},
5 Client, EvalRuns, RequestOptions,
6};
7
8pub 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 pub fn runs(&self, eval_id: &str) -> EvalRuns<'_, C> {
25 EvalRuns::new(self.client, eval_id)
26 }
27
28 #[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 #[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 #[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 #[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 #[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}