async_openai_alt/
batches.rs1use serde::Serialize;
2
3use crate::{
4 config::Config,
5 error::OpenAIError,
6 types::{Batch, BatchRequest, ListBatchesResponse},
7 Client,
8};
9
10pub struct Batches<'c, C: Config> {
14 client: &'c Client<C>,
15}
16
17impl<'c, C: Config> Batches<'c, C> {
18 pub fn new(client: &'c Client<C>) -> Self {
19 Self { client }
20 }
21
22 pub async fn create(&self, request: BatchRequest) -> Result<Batch, OpenAIError> {
24 self.client.post("/batches", request).await
25 }
26
27 pub async fn list<Q>(&self, query: &Q) -> Result<ListBatchesResponse, OpenAIError>
29 where
30 Q: Serialize + ?Sized,
31 {
32 self.client.get_with_query("/batches", query).await
33 }
34
35 pub async fn retrieve(&self, batch_id: &str) -> Result<Batch, OpenAIError> {
37 self.client.get(&format!("/batches/{batch_id}")).await
38 }
39
40 pub async fn cancel(&self, batch_id: &str) -> Result<Batch, OpenAIError> {
42 self.client
43 .post(
44 &format!("/batches/{batch_id}/cancel"),
45 serde_json::json!({}),
46 )
47 .await
48 }
49}