dynamo_async_openai/
vector_store_file_batches.rs

1// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3//
4// Based on https://github.com/64bit/async-openai/ by Himanshu Neema
5// Original Copyright (c) 2022 Himanshu Neema
6// Licensed under MIT License (see ATTRIBUTIONS-Rust.md)
7//
8// Modifications Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
9// Licensed under Apache 2.0
10
11use serde::Serialize;
12
13use crate::{
14    Client,
15    config::Config,
16    error::OpenAIError,
17    types::{
18        CreateVectorStoreFileBatchRequest, ListVectorStoreFilesResponse, VectorStoreFileBatchObject,
19    },
20};
21
22/// Vector store file batches represent operations to add multiple files to a vector store.
23///
24/// Related guide: [File Search](https://platform.openai.com/docs/assistants/tools/file-search)
25pub struct VectorStoreFileBatches<'c, C: Config> {
26    client: &'c Client<C>,
27    pub vector_store_id: String,
28}
29
30impl<'c, C: Config> VectorStoreFileBatches<'c, C> {
31    pub fn new(client: &'c Client<C>, vector_store_id: &str) -> Self {
32        Self {
33            client,
34            vector_store_id: vector_store_id.into(),
35        }
36    }
37
38    /// Create vector store file batch
39    #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
40    pub async fn create(
41        &self,
42        request: CreateVectorStoreFileBatchRequest,
43    ) -> Result<VectorStoreFileBatchObject, OpenAIError> {
44        self.client
45            .post(
46                &format!("/vector_stores/{}/file_batches", &self.vector_store_id),
47                request,
48            )
49            .await
50    }
51
52    /// Retrieves a vector store file batch.
53    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
54    pub async fn retrieve(
55        &self,
56        batch_id: &str,
57    ) -> Result<VectorStoreFileBatchObject, OpenAIError> {
58        self.client
59            .get(&format!(
60                "/vector_stores/{}/file_batches/{batch_id}",
61                &self.vector_store_id
62            ))
63            .await
64    }
65
66    /// Cancel a vector store file batch. This attempts to cancel the processing of files in this batch as soon as possible.
67    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
68    pub async fn cancel(&self, batch_id: &str) -> Result<VectorStoreFileBatchObject, OpenAIError> {
69        self.client
70            .post(
71                &format!(
72                    "/vector_stores/{}/file_batches/{batch_id}/cancel",
73                    &self.vector_store_id
74                ),
75                serde_json::json!({}),
76            )
77            .await
78    }
79
80    /// Returns a list of vector store files in a batch.
81    #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
82    pub async fn list<Q>(
83        &self,
84        batch_id: &str,
85        query: &Q,
86    ) -> Result<ListVectorStoreFilesResponse, OpenAIError>
87    where
88        Q: Serialize + ?Sized,
89    {
90        self.client
91            .get_with_query(
92                &format!(
93                    "/vector_stores/{}/file_batches/{batch_id}/files",
94                    &self.vector_store_id
95                ),
96                &query,
97            )
98            .await
99    }
100}