zai-rs 0.5.0

一个 Rust SDK, 用于调用 智谱AI API
Documentation
use serde::{Deserialize, Serialize};

use super::types::BatchItem;
use crate::{ZaiResult, client::ZaiClient};

/// Empty body for cancel API (serializes to `{}`)
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct CancelBatchBody {}

/// Cancel a running batch (POST /paas/v4/batches/{batch_id}/cancel)
pub struct CancelBatchRequest {
    batch_id: String,
    /// Empty JSON body
    body: CancelBatchBody,
}

impl CancelBatchRequest {
    /// Create a new cancel request for the given batch_id
    pub fn new(batch_id: impl Into<String>) -> Self {
        Self {
            batch_id: batch_id.into(),
            body: CancelBatchBody::default(),
        }
    }

    /// Send the request via a [`ZaiClient`] and parse typed response
    pub async fn send_via(&self, client: &ZaiClient) -> ZaiResult<CancelBatchResponse> {
        let route = crate::client::routes::BATCHES_CANCEL;
        let url = client.endpoints().resolve_route(route, &[&self.batch_id])?;
        client
            .send_json::<_, CancelBatchResponse>(route.method(), url, &self.body)
            .await
    }
}

/// Response type: a single Batch object
pub type CancelBatchResponse = BatchItem;