async_openai/vectorstores/
vector_store_file_batches.rs

1use crate::{
2    config::Config,
3    error::OpenAIError,
4    types::vectorstores::{
5        CreateVectorStoreFileBatchRequest, ListVectorStoreFilesResponse, VectorStoreFileBatchObject,
6    },
7    Client, RequestOptions,
8};
9
10/// Vector store file batches represent operations to add multiple files to a vector store.
11///
12/// Related guide: [File Search](https://platform.openai.com/docs/assistants/tools/file-search)
13pub struct VectorStoreFileBatches<'c, C: Config> {
14    client: &'c Client<C>,
15    pub vector_store_id: String,
16    pub(crate) request_options: RequestOptions,
17}
18
19impl<'c, C: Config> VectorStoreFileBatches<'c, C> {
20    pub fn new(client: &'c Client<C>, vector_store_id: &str) -> Self {
21        Self {
22            client,
23            vector_store_id: vector_store_id.into(),
24            request_options: RequestOptions::new(),
25        }
26    }
27
28    /// Create vector store file batch
29    #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
30    pub async fn create(
31        &self,
32        request: CreateVectorStoreFileBatchRequest,
33    ) -> Result<VectorStoreFileBatchObject, OpenAIError> {
34        self.client
35            .post(
36                &format!("/vector_stores/{}/file_batches", &self.vector_store_id),
37                request,
38                &self.request_options,
39            )
40            .await
41    }
42
43    /// Retrieves a vector store file batch.
44    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
45    pub async fn retrieve(
46        &self,
47        batch_id: &str,
48    ) -> Result<VectorStoreFileBatchObject, OpenAIError> {
49        self.client
50            .get(
51                &format!(
52                    "/vector_stores/{}/file_batches/{batch_id}",
53                    &self.vector_store_id
54                ),
55                &self.request_options,
56            )
57            .await
58    }
59
60    /// Cancel a vector store file batch. This attempts to cancel the processing of files in this batch as soon as possible.
61    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
62    pub async fn cancel(&self, batch_id: &str) -> Result<VectorStoreFileBatchObject, OpenAIError> {
63        self.client
64            .post(
65                &format!(
66                    "/vector_stores/{}/file_batches/{batch_id}/cancel",
67                    &self.vector_store_id
68                ),
69                serde_json::json!({}),
70                &self.request_options,
71            )
72            .await
73    }
74
75    /// Returns a list of vector store files in a batch.
76    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
77    pub async fn list_files(
78        &self,
79        batch_id: &str,
80    ) -> Result<ListVectorStoreFilesResponse, OpenAIError> {
81        self.client
82            .get(
83                &format!(
84                    "/vector_stores/{}/file_batches/{batch_id}/files",
85                    &self.vector_store_id
86                ),
87                &self.request_options,
88            )
89            .await
90    }
91}