Skip to main content

openai_interface/vector_stores/files/
delete.rs

1//! Delete a vector store file via
2//! `DELETE /vector_stores/{vector_store_id}/files/{file_id}`.
3//!
4//! > ![warn] This module is untested!
5//! > If you encounter any issues, please report them on the repository.
6
7use url::Url;
8
9use crate::{
10    errors::OapiError,
11    rest::delete::{Delete, DeleteNoStream},
12};
13
14/// Deletes a file from a vector store.
15#[derive(Debug, Clone)]
16pub struct DeleteVectorStoreFileRequest<'a> {
17    /// The ID of the vector store, e.g. `vs_...`.
18    pub vector_store_id: &'a str,
19    /// The ID of the file association to delete, e.g. `vsf_...`.
20    pub file_id: &'a str,
21}
22
23impl Delete for DeleteVectorStoreFileRequest<'_> {
24    /// Builds the URL for the request.
25    ///
26    /// `base_url` should be like <https://api.openai.com/v1>
27    fn build_url(&self, base_url: &str) -> Result<String, OapiError> {
28        let mut url = Url::parse(base_url.trim_end_matches('/')).map_err(OapiError::UrlError)?;
29        url.path_segments_mut()
30            .map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
31            .push("vector_stores")
32            .push(self.vector_store_id)
33            .push("files")
34            .push(self.file_id);
35        Ok(url.to_string())
36    }
37}
38
39impl DeleteNoStream for DeleteVectorStoreFileRequest<'_> {
40    type Response = DeleteVectorStoreFileResponse;
41}
42
43/// The response of a vector store file deletion.
44#[derive(Debug, Clone, serde::Deserialize)]
45pub struct DeleteVectorStoreFileResponse {
46    /// The ID of the file association that was deleted.
47    pub id: String,
48    /// Whether the file was deleted successfully.
49    pub deleted: bool,
50    /// The object type (`vector_store.file.deleted`), if the provider
51    /// sends it.
52    #[serde(default)]
53    pub object: Option<String>,
54}
55
56crate::impl_from_str!(DeleteVectorStoreFileResponse);