async_openai/vectorstores/
vector_store_file_batches.rs1use crate::{
2 config::Config,
3 error::OpenAIError,
4 types::vectorstores::{
5 CreateVectorStoreFileBatchRequest, ListVectorStoreFilesResponse, VectorStoreFileBatchObject,
6 },
7 Client, RequestOptions,
8};
9
10pub 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 #[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 #[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 #[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 #[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}