Skip to main content

openai_interface/vector_stores/
create.rs

1//! Create a vector store via `POST /vector_stores`.
2//!
3//! > ![warn] This module is untested!
4//! > If you encounter any issues, please report them on the repository.
5
6use serde::{Deserialize, Serialize};
7use url::Url;
8
9use crate::{
10    errors::OapiError,
11    rest::post::{Post, PostNoStream},
12    vector_stores::VectorStore,
13};
14
15crate::request_body! {
16    /// Creates a vector store.
17    #[derive(Debug, Clone, Serialize, Deserialize, Default)]
18    pub struct CreateVectorStoreRequest {
19        /// The name of the vector store.
20        #[serde(skip_serializing_if = "Option::is_none")]
21        pub name: Option<String>,
22        /// The IDs of files to add to the store right away.
23        #[serde(skip_serializing_if = "Option::is_none")]
24        pub file_ids: Option<Vec<String>>,
25        /// The expiration policy of the store, as raw JSON
26        /// (`{"anchor": "last_active_at", "days": N}`).
27        #[serde(skip_serializing_if = "Option::is_none")]
28        pub expires_after: Option<serde_json::Value>,
29        /// Arbitrary key-value metadata (up to 16 pairs) attached to the
30        /// store.
31        #[serde(skip_serializing_if = "Option::is_none")]
32        pub metadata: Option<std::collections::HashMap<String, String>>,
33    }
34}
35
36impl Post for CreateVectorStoreRequest {
37    fn is_streaming(&self) -> bool {
38        false
39    }
40
41    /// Builds the URL for the request.
42    ///
43    /// `base_url` should be like <https://api.openai.com/v1>
44    fn build_url(&self, base_url: &str) -> Result<String, OapiError> {
45        let mut url = Url::parse(base_url.trim_end_matches('/')).map_err(OapiError::UrlError)?;
46        url.path_segments_mut()
47            .map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
48            .push("vector_stores");
49        Ok(url.to_string())
50    }
51}
52
53impl PostNoStream for CreateVectorStoreRequest {
54    type Response = VectorStore;
55}