openai-interface 0.14.0

A low-level Rust interface for the OpenAI API
Documentation
//! Complete a vector store file batch via
//! `POST /vector_stores/{vector_store_id}/file_batches/{batch_id}/complete`.
//!
//! > ![warn] This module is untested!
//! > If you encounter any issues, please report them on the repository.
//!
//! This endpoint exists for batch flows where files are attached
//! incrementally (the official assistants-style flow); on OpenAI's
//! current API it is effectively a no-op that returns the batch as
//! `completed`.

use url::Url;

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

/// Marks a file batch as complete.
#[derive(Debug, Clone)]
pub struct CompleteVectorStoreFileBatchRequest<'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 CompleteVectorStoreFileBatchRequest<'_> {
    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("complete");
        Ok(url.to_string())
    }
}

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