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::Serialize;
7use url::Url;
8
9use crate::{
10    errors::OapiError,
11    evals::Eval,
12    rest::post::{Post, PostNoStream},
13};
14
15/// Creates an eval.
16#[derive(Debug, Clone, Serialize)]
17pub struct CreateEvalRequest {
18    /// The name of the eval.
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub name: Option<String>,
21    /// The configuration of the eval (the schema of the test cases),
22    /// as raw JSON.
23    pub data_source_config: serde_json::Value,
24    /// The testing criteria (graders) applied by the eval, as raw
25    /// JSON.
26    pub testing_criteria: Vec<serde_json::Value>,
27    /// Arbitrary key-value metadata (up to 16 pairs) attached to the
28    /// eval.
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub metadata: Option<std::collections::HashMap<String, String>>,
31    /// Additional JSON properties flattened into the request body, for
32    /// fields not covered by the typed struct.
33    #[serde(flatten, skip_serializing_if = "Option::is_none")]
34    pub extra_body: Option<serde_json::Map<String, serde_json::Value>>,
35}
36
37impl Post for CreateEvalRequest {
38    fn is_streaming(&self) -> bool {
39        false
40    }
41
42    /// Builds the URL for the request.
43    ///
44    /// `base_url` should be like <https://api.openai.com/v1>
45    fn build_url(&self, base_url: &str) -> Result<String, OapiError> {
46        let mut url = Url::parse(base_url.trim_end_matches('/')).map_err(OapiError::UrlError)?;
47        url.path_segments_mut()
48            .map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
49            .push("evals");
50        Ok(url.to_string())
51    }
52}
53
54impl PostNoStream for CreateEvalRequest {
55    type Response = Eval;
56}