Skip to main content

openai_interface/evals/
delete.rs

1//! Delete an eval via `DELETE /evals/{eval_id}`.
2//!
3//! > ![warn] This module is untested!
4//! > If you encounter any issues, please report them on the repository.
5
6use url::Url;
7
8use crate::{
9    errors::OapiError,
10    rest::delete::{Delete, DeleteNoStream},
11};
12
13/// Deletes an eval by its ID.
14#[derive(Debug, Clone)]
15pub struct DeleteEvalRequest<'a> {
16    /// The ID of the eval to delete, e.g. `eval_...`.
17    pub eval_id: &'a str,
18}
19
20impl Delete for DeleteEvalRequest<'_> {
21    /// Builds the URL for the request.
22    ///
23    /// `base_url` should be like <https://api.openai.com/v1>
24    fn build_url(&self, base_url: &str) -> Result<String, OapiError> {
25        let mut url = Url::parse(base_url.trim_end_matches('/')).map_err(OapiError::UrlError)?;
26        url.path_segments_mut()
27            .map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
28            .push("evals")
29            .push(self.eval_id);
30        Ok(url.to_string())
31    }
32}
33
34impl DeleteNoStream for DeleteEvalRequest<'_> {
35    type Response = DeleteEvalResponse;
36}
37
38/// The response of an eval deletion.
39#[derive(Debug, Clone, serde::Deserialize)]
40pub struct DeleteEvalResponse {
41    /// The ID of the eval that was deleted.
42    pub id: String,
43    /// Whether the eval was deleted successfully.
44    pub deleted: bool,
45    /// The object type (`eval.deleted`), if the provider sends it.
46    #[serde(default)]
47    pub object: Option<String>,
48}
49
50crate::impl_from_str!(DeleteEvalResponse);