async_openai_alt/
vector_store_file_batches.rs

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