Skip to main content

openai_interface/evals/
update.rs

1//! Update an eval via `POST /evals/{eval_id}`.
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/// Updates an eval (currently only its name and metadata).
16#[derive(Debug, Clone, Serialize, Default)]
17pub struct UpdateEvalRequest<'a> {
18    /// The ID of the eval to update, e.g. `eval_...`.
19    #[serde(skip)]
20    pub eval_id: &'a str,
21    /// The new name of the eval.
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub name: Option<String>,
24    /// The new metadata of the eval.
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub metadata: Option<std::collections::HashMap<String, String>>,
27    /// Additional JSON properties flattened into the request body, for
28    /// fields not covered by the typed struct.
29    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
30    pub extra_body_map: Option<serde_json::Map<String, serde_json::Value>>,
31}
32
33impl Post for UpdateEvalRequest<'_> {
34    fn is_streaming(&self) -> bool {
35        false
36    }
37
38    /// Builds the URL for the request.
39    ///
40    /// `base_url` should be like <https://api.openai.com/v1>
41    fn build_url(&self, base_url: &str) -> Result<String, OapiError> {
42        let mut url = Url::parse(base_url.trim_end_matches('/')).map_err(OapiError::UrlError)?;
43        url.path_segments_mut()
44            .map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
45            .push("evals")
46            .push(self.eval_id);
47        Ok(url.to_string())
48    }
49}
50
51impl PostNoStream for UpdateEvalRequest<'_> {
52    type Response = Eval;
53}