Skip to main content

openai_interface/fine_tuning/jobs/
retrieve.rs

1//! Retrieve a fine-tuning job via `GET /fine_tuning/jobs/{job_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    fine_tuning::FineTuningJob,
11    rest::get::{Get, GetNoStream},
12};
13
14/// Retrieves a fine-tuning job by its ID.
15#[derive(Debug, Clone)]
16pub struct RetrieveFineTuningJobRequest<'a> {
17    /// The ID of the job to retrieve, e.g. `ftjob_...`.
18    pub job_id: &'a str,
19}
20
21impl Get for RetrieveFineTuningJobRequest<'_> {
22    /// Builds the URL for the request.
23    ///
24    /// `base_url` should be like <https://api.openai.com/v1>
25    fn build_url(&self, base_url: &str) -> Result<String, OapiError> {
26        let mut url = Url::parse(base_url.trim_end_matches('/')).map_err(OapiError::UrlError)?;
27        url.path_segments_mut()
28            .map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
29            .push("fine_tuning")
30            .push("jobs")
31            .push(self.job_id);
32        Ok(url.to_string())
33    }
34}
35
36impl GetNoStream for RetrieveFineTuningJobRequest<'_> {
37    type Response = FineTuningJob;
38}