Skip to main content

openai_interface/evals/runs/
cancel.rs

1//! Cancel an eval run via `POST /evals/{eval_id}/runs/{run_id}/cancel`.
2//!
3//! > ![warn] This module is untested!
4//! > If you encounter any issues, please report them on the repository.
5//!
6//! Only runs that have not finished yet can be cancelled.
7
8use url::Url;
9
10use crate::{
11    errors::OapiError,
12    evals::runs::EvalRun,
13    rest::post::{Post, PostNoStream},
14};
15
16/// Cancels an eval run by its ID.
17#[derive(Debug, Clone, serde::Serialize)]
18pub struct CancelEvalRunRequest<'a> {
19    /// The ID of the eval, e.g. `eval_...`.
20    #[serde(skip)]
21    pub eval_id: &'a str,
22    /// The ID of the run to cancel, e.g. `evalrun_...`.
23    #[serde(skip)]
24    pub run_id: &'a str,
25}
26
27impl Post for CancelEvalRunRequest<'_> {
28    fn is_streaming(&self) -> bool {
29        false
30    }
31
32    /// Builds the URL for the request.
33    ///
34    /// `base_url` should be like <https://api.openai.com/v1>
35    fn build_url(&self, base_url: &str) -> Result<String, OapiError> {
36        let mut url = Url::parse(base_url.trim_end_matches('/')).map_err(OapiError::UrlError)?;
37        url.path_segments_mut()
38            .map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
39            .push("evals")
40            .push(self.eval_id)
41            .push("runs")
42            .push(self.run_id)
43            .push("cancel");
44        Ok(url.to_string())
45    }
46}
47
48impl PostNoStream for CancelEvalRunRequest<'_> {
49    type Response = EvalRun;
50}