Skip to main content

openai_interface/fine_tuning/
models.rs

1//! Fine-tuning model endpoints under `/fine_tuning/models`.
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    rest::post::{Post, PostNoStream},
11};
12
13/// The body of `POST /fine_tuning/models/{model}` (restore).
14///
15/// The path parameter is carried on the struct but skipped when
16/// serializing the (empty) JSON body.
17#[derive(Debug, Clone, serde::Serialize)]
18pub struct RestoreFineTunedModelRequest<'a> {
19    /// The fine-tuned model to restore, e.g. `ft:gpt-4o:...`.
20    #[serde(skip)]
21    pub model: &'a str,
22}
23
24impl Post for RestoreFineTunedModelRequest<'_> {
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("models")
38            .push(self.model);
39        Ok(url.to_string())
40    }
41}
42
43impl PostNoStream for RestoreFineTunedModelRequest<'_> {
44    type Response = RestoreFineTunedModelResponse;
45}
46
47/// The response of restoring a fine-tuned model.
48#[derive(Debug, Clone, serde::Deserialize)]
49pub struct RestoreFineTunedModelResponse {
50    /// The fine-tuned model that was restored.
51    pub model: String,
52    /// The object type (`fine_tuning.model.restore`), if the provider
53    /// sends it.
54    #[serde(default)]
55    pub object: Option<String>,
56}
57
58crate::impl_from_str!(RestoreFineTunedModelResponse);