use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
#[non_exhaustive]
pub enum BatchStatus {
#[serde(rename = "validating")]
Validating,
#[serde(rename = "failed")]
Failed,
#[serde(rename = "in_progress")]
InProgress,
#[serde(rename = "finalizing")]
Finalizing,
#[serde(rename = "completed")]
Completed,
#[serde(rename = "expired")]
Expired,
#[serde(rename = "cancelling")]
Cancelling,
#[serde(rename = "cancelled")]
Cancelled,
}
#[derive(Debug, Clone, Serialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct BatchCreateRequest {
pub input_file_id: String,
pub endpoint: String,
pub completion_window: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<std::collections::HashMap<String, String>>,
}
impl BatchCreateRequest {
pub fn new(
input_file_id: impl Into<String>,
endpoint: impl Into<String>,
completion_window: impl Into<String>,
) -> Self {
Self {
input_file_id: input_file_id.into(),
endpoint: endpoint.into(),
completion_window: completion_window.into(),
metadata: None,
}
}
}
#[derive(Debug, Clone, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct Batch {
pub id: String,
pub object: String,
pub endpoint: String,
pub input_file_id: String,
pub completion_window: String,
pub status: BatchStatus,
pub created_at: i64,
#[serde(default)]
pub output_file_id: Option<String>,
#[serde(default)]
pub error_file_id: Option<String>,
#[serde(default)]
pub in_progress_at: Option<i64>,
#[serde(default)]
pub completed_at: Option<i64>,
#[serde(default)]
pub failed_at: Option<i64>,
#[serde(default)]
pub cancelled_at: Option<i64>,
#[serde(default)]
pub expired_at: Option<i64>,
#[serde(default)]
pub request_counts: Option<BatchRequestCounts>,
#[serde(default)]
pub metadata: Option<std::collections::HashMap<String, String>>,
}
#[derive(Debug, Clone, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct BatchRequestCounts {
pub total: i64,
pub completed: i64,
pub failed: i64,
}
#[derive(Debug, Clone, Deserialize)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct BatchList {
pub object: String,
pub data: Vec<Batch>,
#[serde(default)]
pub has_more: Option<bool>,
#[serde(default)]
pub first_id: Option<String>,
#[serde(default)]
pub last_id: Option<String>,
}
#[derive(Debug, Clone, Default)]
#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
pub struct BatchListParams {
pub after: Option<String>,
pub limit: Option<i64>,
}
impl BatchListParams {
pub fn new() -> Self {
Self::default()
}
pub fn after(mut self, after: impl Into<String>) -> Self {
self.after = Some(after.into());
self
}
pub fn limit(mut self, limit: i64) -> Self {
self.limit = Some(limit);
self
}
pub fn to_query(&self) -> Vec<(String, String)> {
let mut q = Vec::new();
if let Some(ref after) = self.after {
q.push(("after".into(), after.clone()));
}
if let Some(limit) = self.limit {
q.push(("limit".into(), limit.to_string()));
}
q
}
}