async_openai_wasm/
vector_stores.rs1use serde::Serialize;
2
3use crate::{
4 config::Config,
5 error::OpenAIError,
6 types::{
7 CreateVectorStoreRequest, DeleteVectorStoreResponse, ListVectorStoresResponse,
8 UpdateVectorStoreRequest, VectorStoreObject,
9 },
10 vector_store_file_batches::VectorStoreFileBatches,
11 Client, VectorStoreFiles,
12};
13
14pub struct VectorStores<'c, C: Config> {
15 client: &'c Client<C>,
16}
17
18impl<'c, C: Config> VectorStores<'c, C> {
19 pub fn new(client: &'c Client<C>) -> Self {
20 Self { client }
21 }
22
23 pub fn files(&self, vector_store_id: &str) -> VectorStoreFiles<C> {
25 VectorStoreFiles::new(self.client, vector_store_id)
26 }
27
28 pub fn file_batches(&self, vector_store_id: &str) -> VectorStoreFileBatches<C> {
30 VectorStoreFileBatches::new(self.client, vector_store_id)
31 }
32
33 pub async fn create(
35 &self,
36 request: CreateVectorStoreRequest,
37 ) -> Result<VectorStoreObject, OpenAIError> {
38 self.client.post("/vector_stores", request).await
39 }
40
41 pub async fn retrieve(&self, vector_store_id: &str) -> Result<VectorStoreObject, OpenAIError> {
43 self.client
44 .get(&format!("/vector_stores/{vector_store_id}"))
45 .await
46 }
47
48 pub async fn list<Q>(&self, query: &Q) -> Result<ListVectorStoresResponse, OpenAIError>
50 where
51 Q: Serialize + ?Sized,
52 {
53 self.client.get_with_query("/vector_stores", query).await
54 }
55
56 pub async fn delete(
58 &self,
59 vector_store_id: &str,
60 ) -> Result<DeleteVectorStoreResponse, OpenAIError> {
61 self.client
62 .delete(&format!("/vector_stores/{vector_store_id}"))
63 .await
64 }
65
66 pub async fn update(
68 &self,
69 vector_store_id: &str,
70 request: UpdateVectorStoreRequest,
71 ) -> Result<VectorStoreObject, OpenAIError> {
72 self.client
73 .post(&format!("/vector_stores/{vector_store_id}"), request)
74 .await
75 }
76}