openai-interface 0.14.0

A low-level Rust interface for the OpenAI API
Documentation
//! Fine-tuning model endpoints under `/fine_tuning/models`.
//!
//! > ![warn] This module is untested!
//! > If you encounter any issues, please report them on the repository.

use url::Url;

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

/// The body of `POST /fine_tuning/models/{model}` (restore).
///
/// The path parameter is carried on the struct but skipped when
/// serializing the (empty) JSON body.
#[derive(Debug, Clone, serde::Serialize)]
pub struct RestoreFineTunedModelRequest<'a> {
    /// The fine-tuned model to restore, e.g. `ft:gpt-4o:...`.
    #[serde(skip)]
    pub model: &'a str,
}

impl Post for RestoreFineTunedModelRequest<'_> {
    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("fine_tuning")
            .push("models")
            .push(self.model);
        Ok(url.to_string())
    }
}

impl PostNoStream for RestoreFineTunedModelRequest<'_> {
    type Response = RestoreFineTunedModelResponse;
}

/// The response of restoring a fine-tuned model.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct RestoreFineTunedModelResponse {
    /// The fine-tuned model that was restored.
    pub model: String,
    /// The object type (`fine_tuning.model.restore`), if the provider
    /// sends it.
    #[serde(default)]
    pub object: Option<String>,
}

crate::impl_from_str!(RestoreFineTunedModelResponse);