#![allow(clippy::needless_return, clippy::into_iter_on_ref)]
use super::{configuration, ContentType, Error};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::{de::Error as _, Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CancelVectorStoreFileBatchError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateVectorStoreError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateVectorStoreFileError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateVectorStoreFileBatchError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteVectorStoreError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteVectorStoreFileError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetVectorStoreError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetVectorStoreFileError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetVectorStoreFileBatchError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListFilesInVectorStoreBatchError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListVectorStoreFilesError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListVectorStoresError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ModifyVectorStoreError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RetrieveVectorStoreFileContentError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SearchVectorStoreError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateVectorStoreFileAttributesError {
UnknownValue(serde_json::Value),
}
#[bon::builder]
pub async fn cancel_vector_store_file_batch(
configuration: &configuration::Configuration,
vector_store_id: &str,
batch_id: &str,
) -> Result<models::VectorStoreFileBatchObject, Error<CancelVectorStoreFileBatchError>> {
let p_path_vector_store_id = vector_store_id;
let p_path_batch_id = batch_id;
let uri_str = format!(
"{}/vector_stores/{vector_store_id}/file_batches/{batch_id}/cancel",
configuration.base_path,
vector_store_id = crate::apis::urlencode(p_path_vector_store_id),
batch_id = crate::apis::urlencode(p_path_batch_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::VectorStoreFileBatchObject`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::VectorStoreFileBatchObject`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CancelVectorStoreFileBatchError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
#[bon::builder]
pub async fn create_vector_store(
configuration: &configuration::Configuration,
create_vector_store_request: models::CreateVectorStoreRequest,
) -> Result<models::VectorStoreObject, Error<CreateVectorStoreError>> {
let p_body_create_vector_store_request = create_vector_store_request;
let uri_str = format!("{}/vector_stores", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_create_vector_store_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::VectorStoreObject`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::VectorStoreObject`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CreateVectorStoreError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
#[bon::builder]
pub async fn create_vector_store_file(
configuration: &configuration::Configuration,
vector_store_id: &str,
create_vector_store_file_request: models::CreateVectorStoreFileRequest,
) -> Result<models::VectorStoreFileObject, Error<CreateVectorStoreFileError>> {
let p_path_vector_store_id = vector_store_id;
let p_body_create_vector_store_file_request = create_vector_store_file_request;
let uri_str = format!(
"{}/vector_stores/{vector_store_id}/files",
configuration.base_path,
vector_store_id = crate::apis::urlencode(p_path_vector_store_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_create_vector_store_file_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::VectorStoreFileObject`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::VectorStoreFileObject`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CreateVectorStoreFileError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
#[bon::builder]
pub async fn create_vector_store_file_batch(
configuration: &configuration::Configuration,
vector_store_id: &str,
create_vector_store_file_batch_request: models::CreateVectorStoreFileBatchRequest,
) -> Result<models::VectorStoreFileBatchObject, Error<CreateVectorStoreFileBatchError>> {
let p_path_vector_store_id = vector_store_id;
let p_body_create_vector_store_file_batch_request = create_vector_store_file_batch_request;
let uri_str = format!(
"{}/vector_stores/{vector_store_id}/file_batches",
configuration.base_path,
vector_store_id = crate::apis::urlencode(p_path_vector_store_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_create_vector_store_file_batch_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::VectorStoreFileBatchObject`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::VectorStoreFileBatchObject`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CreateVectorStoreFileBatchError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
#[bon::builder]
pub async fn delete_vector_store(
configuration: &configuration::Configuration,
vector_store_id: &str,
) -> Result<models::DeleteVectorStoreResponse, Error<DeleteVectorStoreError>> {
let p_path_vector_store_id = vector_store_id;
let uri_str = format!(
"{}/vector_stores/{vector_store_id}",
configuration.base_path,
vector_store_id = crate::apis::urlencode(p_path_vector_store_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteVectorStoreResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::DeleteVectorStoreResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<DeleteVectorStoreError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
#[bon::builder]
pub async fn delete_vector_store_file(
configuration: &configuration::Configuration,
vector_store_id: &str,
file_id: &str,
) -> Result<models::DeleteVectorStoreFileResponse, Error<DeleteVectorStoreFileError>> {
let p_path_vector_store_id = vector_store_id;
let p_path_file_id = file_id;
let uri_str = format!(
"{}/vector_stores/{vector_store_id}/files/{file_id}",
configuration.base_path,
vector_store_id = crate::apis::urlencode(p_path_vector_store_id),
file_id = crate::apis::urlencode(p_path_file_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteVectorStoreFileResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::DeleteVectorStoreFileResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<DeleteVectorStoreFileError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
#[bon::builder]
pub async fn get_vector_store(
configuration: &configuration::Configuration,
vector_store_id: &str,
) -> Result<models::VectorStoreObject, Error<GetVectorStoreError>> {
let p_path_vector_store_id = vector_store_id;
let uri_str = format!(
"{}/vector_stores/{vector_store_id}",
configuration.base_path,
vector_store_id = crate::apis::urlencode(p_path_vector_store_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::VectorStoreObject`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::VectorStoreObject`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetVectorStoreError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
#[bon::builder]
pub async fn get_vector_store_file(
configuration: &configuration::Configuration,
vector_store_id: &str,
file_id: &str,
) -> Result<models::VectorStoreFileObject, Error<GetVectorStoreFileError>> {
let p_path_vector_store_id = vector_store_id;
let p_path_file_id = file_id;
let uri_str = format!(
"{}/vector_stores/{vector_store_id}/files/{file_id}",
configuration.base_path,
vector_store_id = crate::apis::urlencode(p_path_vector_store_id),
file_id = crate::apis::urlencode(p_path_file_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::VectorStoreFileObject`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::VectorStoreFileObject`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetVectorStoreFileError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
#[bon::builder]
pub async fn get_vector_store_file_batch(
configuration: &configuration::Configuration,
vector_store_id: &str,
batch_id: &str,
) -> Result<models::VectorStoreFileBatchObject, Error<GetVectorStoreFileBatchError>> {
let p_path_vector_store_id = vector_store_id;
let p_path_batch_id = batch_id;
let uri_str = format!(
"{}/vector_stores/{vector_store_id}/file_batches/{batch_id}",
configuration.base_path,
vector_store_id = crate::apis::urlencode(p_path_vector_store_id),
batch_id = crate::apis::urlencode(p_path_batch_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::VectorStoreFileBatchObject`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::VectorStoreFileBatchObject`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetVectorStoreFileBatchError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
#[bon::builder]
pub async fn list_files_in_vector_store_batch(
configuration: &configuration::Configuration,
vector_store_id: &str,
batch_id: &str,
limit: Option<i32>,
order: Option<&str>,
after: Option<&str>,
before: Option<&str>,
filter: Option<&str>,
) -> Result<models::ListVectorStoreFilesResponse, Error<ListFilesInVectorStoreBatchError>> {
let p_path_vector_store_id = vector_store_id;
let p_path_batch_id = batch_id;
let p_query_limit = limit;
let p_query_order = order;
let p_query_after = after;
let p_query_before = before;
let p_query_filter = filter;
let uri_str = format!(
"{}/vector_stores/{vector_store_id}/file_batches/{batch_id}/files",
configuration.base_path,
vector_store_id = crate::apis::urlencode(p_path_vector_store_id),
batch_id = crate::apis::urlencode(p_path_batch_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_order {
req_builder = req_builder.query(&[("order", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_after {
req_builder = req_builder.query(&[("after", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_before {
req_builder = req_builder.query(&[("before", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_filter {
req_builder = req_builder.query(&[("filter", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListVectorStoreFilesResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ListVectorStoreFilesResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListFilesInVectorStoreBatchError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
#[bon::builder]
pub async fn list_vector_store_files(
configuration: &configuration::Configuration,
vector_store_id: &str,
limit: Option<i32>,
order: Option<&str>,
after: Option<&str>,
before: Option<&str>,
filter: Option<&str>,
) -> Result<models::ListVectorStoreFilesResponse, Error<ListVectorStoreFilesError>> {
let p_path_vector_store_id = vector_store_id;
let p_query_limit = limit;
let p_query_order = order;
let p_query_after = after;
let p_query_before = before;
let p_query_filter = filter;
let uri_str = format!(
"{}/vector_stores/{vector_store_id}/files",
configuration.base_path,
vector_store_id = crate::apis::urlencode(p_path_vector_store_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_order {
req_builder = req_builder.query(&[("order", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_after {
req_builder = req_builder.query(&[("after", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_before {
req_builder = req_builder.query(&[("before", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_filter {
req_builder = req_builder.query(&[("filter", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListVectorStoreFilesResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ListVectorStoreFilesResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListVectorStoreFilesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
#[bon::builder]
pub async fn list_vector_stores(
configuration: &configuration::Configuration,
limit: Option<i32>,
order: Option<&str>,
after: Option<&str>,
before: Option<&str>,
) -> Result<models::ListVectorStoresResponse, Error<ListVectorStoresError>> {
let p_query_limit = limit;
let p_query_order = order;
let p_query_after = after;
let p_query_before = before;
let uri_str = format!("{}/vector_stores", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_order {
req_builder = req_builder.query(&[("order", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_after {
req_builder = req_builder.query(&[("after", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_before {
req_builder = req_builder.query(&[("before", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListVectorStoresResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ListVectorStoresResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListVectorStoresError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
#[bon::builder]
pub async fn modify_vector_store(
configuration: &configuration::Configuration,
vector_store_id: &str,
update_vector_store_request: models::UpdateVectorStoreRequest,
) -> Result<models::VectorStoreObject, Error<ModifyVectorStoreError>> {
let p_path_vector_store_id = vector_store_id;
let p_body_update_vector_store_request = update_vector_store_request;
let uri_str = format!(
"{}/vector_stores/{vector_store_id}",
configuration.base_path,
vector_store_id = crate::apis::urlencode(p_path_vector_store_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_update_vector_store_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::VectorStoreObject`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::VectorStoreObject`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ModifyVectorStoreError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
#[bon::builder]
pub async fn retrieve_vector_store_file_content(
configuration: &configuration::Configuration,
vector_store_id: &str,
file_id: &str,
) -> Result<models::VectorStoreFileContentResponse, Error<RetrieveVectorStoreFileContentError>> {
let p_path_vector_store_id = vector_store_id;
let p_path_file_id = file_id;
let uri_str = format!(
"{}/vector_stores/{vector_store_id}/files/{file_id}/content",
configuration.base_path,
vector_store_id = crate::apis::urlencode(p_path_vector_store_id),
file_id = crate::apis::urlencode(p_path_file_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::VectorStoreFileContentResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::VectorStoreFileContentResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<RetrieveVectorStoreFileContentError> =
serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
#[bon::builder]
pub async fn search_vector_store(
configuration: &configuration::Configuration,
vector_store_id: &str,
vector_store_search_request: models::VectorStoreSearchRequest,
) -> Result<models::VectorStoreSearchResultsPage, Error<SearchVectorStoreError>> {
let p_path_vector_store_id = vector_store_id;
let p_body_vector_store_search_request = vector_store_search_request;
let uri_str = format!(
"{}/vector_stores/{vector_store_id}/search",
configuration.base_path,
vector_store_id = crate::apis::urlencode(p_path_vector_store_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_vector_store_search_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::VectorStoreSearchResultsPage`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::VectorStoreSearchResultsPage`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SearchVectorStoreError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
#[bon::builder]
pub async fn update_vector_store_file_attributes(
configuration: &configuration::Configuration,
vector_store_id: &str,
file_id: &str,
update_vector_store_file_attributes_request: models::UpdateVectorStoreFileAttributesRequest,
) -> Result<models::VectorStoreFileObject, Error<UpdateVectorStoreFileAttributesError>> {
let p_path_vector_store_id = vector_store_id;
let p_path_file_id = file_id;
let p_body_update_vector_store_file_attributes_request =
update_vector_store_file_attributes_request;
let uri_str = format!(
"{}/vector_stores/{vector_store_id}/files/{file_id}",
configuration.base_path,
vector_store_id = crate::apis::urlencode(p_path_vector_store_id),
file_id = crate::apis::urlencode(p_path_file_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_update_vector_store_file_attributes_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::VectorStoreFileObject`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::VectorStoreFileObject`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<UpdateVectorStoreFileAttributesError> =
serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}