openai-interface 0.13.0

A low-level Rust interface for the OpenAI API
Documentation
//! Create a vector store file batch via
//! `POST /vector_stores/{vector_store_id}/file_batches`.
//!
//! > ![warn] This module is untested!
//! > If you encounter any issues, please report them on the repository.

use serde::Serialize;
use url::Url;

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

/// Adds up to 500 files to a vector store in one batch.
#[derive(Debug, Clone, Serialize)]
pub struct CreateVectorStoreFileBatchRequest<'a> {
    /// The ID of the vector store, e.g. `vs_...`.
    #[serde(skip)]
    pub vector_store_id: &'a str,
    /// The IDs of the [`FileObject`](crate::files::FileObject)s to add.
    pub file_ids: Vec<String>,
    /// The chunking strategy applied to the files, as raw JSON
    /// (`{"type": "auto"}` or
    /// `{"type": "static", "max_chunk_size_tokens": ..., "chunk_overlap_tokens": ...}`).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub chunking_strategy: Option<serde_json::Value>,
    /// The attributes attached to the files, as raw JSON.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub attributes: Option<serde_json::Value>,
    /// Additional JSON properties flattened into the request body, for
    /// fields not covered by the typed struct.
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_body_map: Option<serde_json::Map<String, serde_json::Value>>,
}

impl Post for CreateVectorStoreFileBatchRequest<'_> {
    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");
        Ok(url.to_string())
    }
}

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