use crate::{
config::Config,
error::OpenAIError,
types::batches::{Batch, BatchRequest, ListBatchesResponse},
Client, RequestOptions,
};
pub struct Batches<'c, C: Config> {
client: &'c Client<C>,
pub(crate) request_options: RequestOptions,
}
impl<'c, C: Config> Batches<'c, C> {
pub fn new(client: &'c Client<C>) -> Self {
Self {
client,
request_options: RequestOptions::new(),
}
}
#[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
pub async fn create(&self, request: BatchRequest) -> Result<Batch, OpenAIError> {
self.client
.post("/batches", request, &self.request_options)
.await
}
#[crate::byot(R = serde::de::DeserializeOwned)]
pub async fn list(&self) -> Result<ListBatchesResponse, OpenAIError> {
self.client.get("/batches", &self.request_options).await
}
#[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
pub async fn retrieve(&self, batch_id: &str) -> Result<Batch, OpenAIError> {
self.client
.get(&format!("/batches/{batch_id}"), &self.request_options)
.await
}
#[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
pub async fn cancel(&self, batch_id: &str) -> Result<Batch, OpenAIError> {
self.client
.post(
&format!("/batches/{batch_id}/cancel"),
serde_json::json!({}),
&self.request_options,
)
.await
}
}