Skip to main content

openai_interface/fine_tuning/jobs/
cancel.rs

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