openai-interface 0.10.0

A low-level Rust interface for the OpenAI API
Documentation
//! Cancel an eval run via `POST /evals/{eval_id}/runs/{run_id}/cancel`.
//!
//! > ![warn] This module is untested!
//! > If you encounter any issues, please report them on the repository.
//!
//! Only runs that have not finished yet can be cancelled.

use url::Url;

use crate::{
    errors::OapiError,
    evals::runs::EvalRun,
    rest::post::{Post, PostNoStream},
};

/// Cancels an eval run by its ID.
#[derive(Debug, Clone, serde::Serialize)]
pub struct CancelEvalRunRequest<'a> {
    /// The ID of the eval, e.g. `eval_...`.
    #[serde(skip)]
    pub eval_id: &'a str,
    /// The ID of the run to cancel, e.g. `evalrun_...`.
    #[serde(skip)]
    pub run_id: &'a str,
}

impl Post for CancelEvalRunRequest<'_> {
    fn is_streaming(&self) -> bool {
        false
    }

    /// 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)
            .push("runs")
            .push(self.run_id)
            .push("cancel");
        Ok(url.to_string())
    }
}

impl PostNoStream for CancelEvalRunRequest<'_> {
    type Response = EvalRun;
}