Skip to main content

openai_interface/vector_stores/files/
retrieve.rs

1//! Retrieve a vector store file via
2//! `GET /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::get::{Get, GetNoStream},
12    vector_stores::VectorStoreFile,
13};
14
15/// Retrieves a file of a vector store by its association ID.
16#[derive(Debug, Clone)]
17pub struct RetrieveVectorStoreFileRequest<'a> {
18    /// The ID of the vector store, e.g. `vs_...`.
19    pub vector_store_id: &'a str,
20    /// The ID of the file association, e.g. `vsf_...`.
21    pub file_id: &'a str,
22}
23
24impl Get for RetrieveVectorStoreFileRequest<'_> {
25    /// Builds the URL for the request.
26    ///
27    /// `base_url` should be like <https://api.openai.com/v1>
28    fn build_url(&self, base_url: &str) -> Result<String, OapiError> {
29        let mut url = Url::parse(base_url.trim_end_matches('/')).map_err(OapiError::UrlError)?;
30        url.path_segments_mut()
31            .map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
32            .push("vector_stores")
33            .push(self.vector_store_id)
34            .push("files")
35            .push(self.file_id);
36        Ok(url.to_string())
37    }
38}
39
40impl GetNoStream for RetrieveVectorStoreFileRequest<'_> {
41    type Response = VectorStoreFile;
42}