use serde::Serialize;
use validator::Validate;
use super::super::traits::*;
use crate::ZaiResult;
use crate::{ZaiError, client::error::codes};
#[derive(Debug, Clone, Serialize, Validate)]
pub struct AudioToTextBody<N>
where
N: ModelName + AudioToText + Serialize,
{
pub model: N,
#[serde(skip_serializing_if = "Option::is_none")]
pub prompt: Option<String>,
#[serde(skip_serializing_if = "Vec::is_empty")]
#[validate(length(max = 100))]
pub hotwords: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub stream: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
#[validate(length(min = 6, max = 64))]
pub request_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[validate(length(min = 6, max = 128))]
pub user_id: Option<String>,
}
impl<N> AudioToTextBody<N>
where
N: ModelName + AudioToText + Serialize,
{
pub fn new(model: N) -> Self {
Self {
model,
prompt: None,
hotwords: Vec::new(),
stream: None,
request_id: None,
user_id: None,
}
}
pub fn with_prompt(mut self, prompt: impl Into<String>) -> Self {
self.prompt = Some(prompt.into());
self
}
pub fn with_hotwords(mut self, hotwords: Vec<String>) -> ZaiResult<Self> {
if hotwords.len() > 100 {
return Err(ZaiError::ApiError {
code: codes::SDK_VALIDATION,
message: "hotwords must contain at most 100 entries".to_string(),
});
}
self.hotwords = hotwords;
Ok(self)
}
pub fn with_stream(mut self, stream: bool) -> Self {
self.stream = Some(stream);
self
}
pub fn with_request_id(mut self, request_id: impl Into<String>) -> Self {
self.request_id = Some(request_id.into());
self
}
pub fn with_user_id(mut self, user_id: impl Into<String>) -> Self {
self.user_id = Some(user_id.into());
self
}
}