1use serde::{Deserialize, Serialize};
2
3use super::types::BatchItem;
4use crate::client::http::HttpClient;
5
6#[derive(Debug, Clone, Serialize, Deserialize, Default)]
8pub struct CancelBatchBody {}
9
10pub struct CancelBatchRequest {
12 pub key: String,
14 url: String,
16 body: CancelBatchBody,
18}
19
20impl CancelBatchRequest {
21 pub fn new(key: String, batch_id: impl AsRef<str>) -> Self {
23 let url = format!(
24 "https://open.bigmodel.cn/api/paas/v4/batches/{}/cancel",
25 batch_id.as_ref()
26 );
27 Self {
28 key,
29 url,
30 body: CancelBatchBody::default(),
31 }
32 }
33
34 pub async fn send(&self) -> anyhow::Result<CancelBatchResponse> {
36 let resp: reqwest::Response = self.post().await?;
37 let parsed = resp.json::<CancelBatchResponse>().await?;
38 Ok(parsed)
39 }
40}
41
42impl HttpClient for CancelBatchRequest {
43 type Body = CancelBatchBody;
44 type ApiUrl = String;
45 type ApiKey = String;
46
47 fn api_url(&self) -> &Self::ApiUrl {
48 &self.url
49 }
50 fn api_key(&self) -> &Self::ApiKey {
51 &self.key
52 }
53 fn body(&self) -> &Self::Body {
54 &self.body
55 }
56}
57
58pub type CancelBatchResponse = BatchItem;