use url::Url;
use crate::{
errors::OapiError,
rest::get::{Get, GetNoStream},
};
#[derive(Debug, Clone)]
pub struct RetrieveVectorStoreFileContentRequest<'a> {
pub vector_store_id: &'a str,
pub file_id: &'a str,
pub extra_query: Option<std::collections::HashMap<String, String>>,
}
impl Get for RetrieveVectorStoreFileContentRequest<'_> {
fn build_url(&self, base_url: &str) -> Result<String, OapiError> {
let mut url = Url::parse(base_url.trim_end_matches('/')).map_err(OapiError::UrlError)?;
url.path_segments_mut()
.map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
.push("vector_stores")
.push(self.vector_store_id)
.push("files")
.push(self.file_id)
.push("content");
if let Some(extra_query) = &self.extra_query {
let mut pairs = url.query_pairs_mut();
for (key, value) in extra_query {
pairs.append_pair(key, value);
}
}
Ok(url.to_string())
}
}
impl GetNoStream for RetrieveVectorStoreFileContentRequest<'_> {
type Response = VectorStoreFileContentResponse;
}
#[derive(Debug, Clone, serde::Deserialize)]
pub struct VectorStoreFileContentChunk {
#[serde(default)]
pub id: Option<String>,
#[serde(default)]
pub object: Option<String>,
#[serde(default)]
pub text: Option<String>,
#[serde(default)]
pub tokens: Option<u64>,
#[serde(default)]
pub attributes: Option<serde_json::Value>,
}
#[derive(Debug, Clone, serde::Deserialize)]
pub struct VectorStoreFileContentResponse {
#[serde(default)]
pub data: Vec<VectorStoreFileContentChunk>,
#[serde(default)]
pub has_more: Option<bool>,
}
crate::impl_from_str!(VectorStoreFileContentResponse);