Skip to main content

openai_interface/evals/
create.rs

1//! Create an eval via `POST /evals`.
2//!
3//! > ![warn] This module is untested!
4//! > If you encounter any issues, please report them on the repository.
5
6use serde::{Deserialize, Serialize};
7use url::Url;
8
9use crate::{
10    errors::OapiError,
11    evals::Eval,
12    rest::post::{Post, PostNoStream},
13};
14
15crate::request_body! {
16    /// Creates an eval.
17    #[derive(Debug, Clone, Serialize, Deserialize)]
18    pub struct CreateEvalRequest {
19        /// The name of the eval.
20        #[serde(skip_serializing_if = "Option::is_none")]
21        pub name: Option<String>,
22        /// The configuration of the eval (the schema of the test cases),
23        /// as raw JSON.
24        pub data_source_config: serde_json::Value,
25        /// The testing criteria (graders) applied by the eval, as raw
26        /// JSON.
27        pub testing_criteria: Vec<serde_json::Value>,
28        /// Arbitrary key-value metadata (up to 16 pairs) attached to the
29        /// eval.
30        #[serde(skip_serializing_if = "Option::is_none")]
31        pub metadata: Option<std::collections::HashMap<String, String>>,
32    }
33}
34
35impl Post for CreateEvalRequest {
36    fn is_streaming(&self) -> bool {
37        false
38    }
39
40    /// Builds the URL for the request.
41    ///
42    /// `base_url` should be like <https://api.openai.com/v1>
43    fn build_url(&self, base_url: &str) -> Result<String, OapiError> {
44        let mut url = Url::parse(base_url.trim_end_matches('/')).map_err(OapiError::UrlError)?;
45        url.path_segments_mut()
46            .map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
47            .push("evals");
48        Ok(url.to_string())
49    }
50}
51
52impl PostNoStream for CreateEvalRequest {
53    type Response = Eval;
54}