openai-interface 0.13.0

A low-level Rust interface for the OpenAI API
Documentation
//! Cancel a vector store file batch via
//! `POST /vector_stores/{vector_store_id}/file_batches/{batch_id}/cancel`.
//!
//! > ![warn] This module is untested!
//! > If you encounter any issues, please report them on the repository.
//!
//! Cancelling aborts processing of the files that have not completed
//! yet; already completed files stay in the store.

use url::Url;

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

/// Cancels a file batch of a vector store.
#[derive(Debug, Clone)]
pub struct CancelVectorStoreFileBatchRequest<'a> {
    /// The ID of the vector store, e.g. `vs_...`.
    #[serde(skip)]
    pub vector_store_id: &'a str,
    /// The ID of the file batch, e.g. `vsfb_...`.
    #[serde(skip)]
    pub batch_id: &'a str,
}

impl Post for CancelVectorStoreFileBatchRequest<'_> {
    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("vector_stores")
            .push(self.vector_store_id)
            .push("file_batches")
            .push(self.batch_id)
            .push("cancel");
        Ok(url.to_string())
    }
}

impl PostNoStream for CancelVectorStoreFileBatchRequest<'_> {
    type Response = VectorStoreFileBatch;
}