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::Serialize;
7use url::Url;
8
9use crate::{
10    errors::OapiError,
11    rest::post::{Post, PostNoStream},
12    vector_stores::VectorStore,
13};
14
15/// Creates a vector store.
16#[derive(Debug, Clone, Serialize, Default)]
17pub struct CreateVectorStoreRequest {
18    /// The name of the vector store.
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub name: Option<String>,
21    /// The IDs of files to add to the store right away.
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub file_ids: Option<Vec<String>>,
24    /// The expiration policy of the store, as raw JSON
25    /// (`{"anchor": "last_active_at", "days": N}`).
26    #[serde(skip_serializing_if = "Option::is_none")]
27    pub expires_after: Option<serde_json::Value>,
28    /// Arbitrary key-value metadata (up to 16 pairs) attached to the
29    /// store.
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub metadata: Option<std::collections::HashMap<String, String>>,
32    /// Additional JSON properties flattened into the request body, for
33    /// fields not covered by the typed struct.
34    #[serde(flatten, skip_serializing_if = "Option::is_none")]
35    pub extra_body: Option<serde_json::Map<String, serde_json::Value>>,
36}
37
38impl Post for CreateVectorStoreRequest {
39    fn is_streaming(&self) -> bool {
40        false
41    }
42
43    /// Builds the URL for the request.
44    ///
45    /// `base_url` should be like <https://api.openai.com/v1>
46    fn build_url(&self, base_url: &str) -> Result<String, OapiError> {
47        let mut url = Url::parse(base_url.trim_end_matches('/')).map_err(OapiError::UrlError)?;
48        url.path_segments_mut()
49            .map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
50            .push("vector_stores");
51        Ok(url.to_string())
52    }
53}
54
55impl PostNoStream for CreateVectorStoreRequest {
56    type Response = VectorStore;
57}