openai-interface 0.14.0

A low-level Rust interface for the OpenAI API
Documentation
//! Delete an eval via `DELETE /evals/{eval_id}`.
//!
//! > ![warn] This module is untested!
//! > If you encounter any issues, please report them on the repository.

use url::Url;

use crate::{
    errors::OapiError,
    rest::delete::{Delete, DeleteNoStream},
};

/// Deletes an eval by its ID.
#[derive(Debug, Clone)]
pub struct DeleteEvalRequest<'a> {
    /// The ID of the eval to delete, e.g. `eval_...`.
    pub eval_id: &'a str,
}

impl Delete for DeleteEvalRequest<'_> {
    /// Builds the URL for the request.
    ///
    /// `base_url` should be like <https://api.openai.com/v1>
    fn build_url(&self, base_url: &str) -> Result<String, OapiError> {
        let mut url = Url::parse(base_url.trim_end_matches('/')).map_err(OapiError::UrlError)?;
        url.path_segments_mut()
            .map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
            .push("evals")
            .push(self.eval_id);
        Ok(url.to_string())
    }
}

impl DeleteNoStream for DeleteEvalRequest<'_> {
    type Response = DeleteEvalResponse;
}

/// The response of an eval deletion.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct DeleteEvalResponse {
    /// The ID of the eval that was deleted.
    pub id: String,
    /// Whether the eval was deleted successfully.
    pub deleted: bool,
    /// The object type (`eval.deleted`), if the provider sends it.
    #[serde(default)]
    pub object: Option<String>,
}

crate::impl_from_str!(DeleteEvalResponse);