use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ImageResponse {
pub created: i64,
pub data: Vec<ImageData>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ImageData {
#[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub b64_json: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub revised_prompt: Option<String>,
}
impl ImageData {
pub fn as_bytes(&self) -> Option<std::result::Result<Vec<u8>, base64::DecodeError>> {
use base64::{engine::general_purpose::STANDARD, Engine};
self.b64_json.as_ref().map(|b64| STANDARD.decode(b64))
}
pub fn has_url(&self) -> bool {
self.url.is_some()
}
pub fn has_b64(&self) -> bool {
self.b64_json.is_some()
}
}