Skip to main content

openai_interface/evals/runs/
create.rs

1//! Create an eval run via `POST /evals/{eval_id}/runs`.
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::runs::EvalRun,
12    rest::post::{Post, PostNoStream},
13};
14
15/// Creates an eval run.
16#[derive(Debug, Clone, Serialize)]
17pub struct CreateEvalRunRequest<'a> {
18    /// The ID of the eval to run, e.g. `eval_...`.
19    #[serde(skip)]
20    pub eval_id: &'a str,
21    /// The name of the run.
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub name: Option<String>,
24    /// The data source of the run (e.g. a completions file or a
25    /// logged-completions query), as raw JSON.
26    pub data_source: serde_json::Value,
27    /// Arbitrary key-value metadata (up to 16 pairs) attached to the
28    /// run.
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub metadata: Option<std::collections::HashMap<String, String>>,
31    /// Whether to run the criteria on a sample of the data source.
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub testing_criteria_sample: Option<serde_json::Value>,
34    /// Additional JSON properties flattened into the request body, for
35    /// fields not covered by the typed struct.
36    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
37    pub extra_body_map: Option<serde_json::Map<String, serde_json::Value>>,
38}
39
40impl Post for CreateEvalRunRequest<'_> {
41    fn is_streaming(&self) -> bool {
42        false
43    }
44
45    /// Builds the URL for the request.
46    ///
47    /// `base_url` should be like <https://api.openai.com/v1>
48    fn build_url(&self, base_url: &str) -> Result<String, OapiError> {
49        let mut url = Url::parse(base_url.trim_end_matches('/')).map_err(OapiError::UrlError)?;
50        url.path_segments_mut()
51            .map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
52            .push("evals")
53            .push(self.eval_id)
54            .push("runs");
55        Ok(url.to_string())
56    }
57}
58
59impl PostNoStream for CreateEvalRunRequest<'_> {
60    type Response = EvalRun;
61}