use serde::Serialize;
use validator::Validate;
use super::{
super::traits::*,
video_request::{Fps, ImageUrl, VideoBody, VideoDuration, VideoQuality, VideoSize},
};
use crate::client::http::HttpClient;
pub struct VideoGenRequest<N>
where
N: ModelName + VideoGen + Serialize,
{
pub key: String,
body: VideoBody<N>,
}
impl<N> VideoGenRequest<N>
where
N: ModelName + VideoGen + Serialize,
{
pub fn new(model: N, key: String) -> Self {
let body = VideoBody::new(model);
Self { key, body }
}
pub fn with_prompt(mut self, prompt: impl Into<String>) -> Self {
self.body = self.body.with_prompt(prompt);
self
}
pub fn with_quality(mut self, quality: VideoQuality) -> Self {
self.body = self.body.with_quality(quality);
self
}
pub fn with_audio(mut self, with_audio: bool) -> Self {
self.body = self.body.with_audio(with_audio);
self
}
pub fn with_watermark_enabled(mut self, watermark_enabled: bool) -> Self {
self.body = self.body.with_watermark_enabled(watermark_enabled);
self
}
pub fn with_image_url(mut self, image_url: ImageUrl) -> Self {
self.body = self.body.with_image_url(image_url);
self
}
pub fn with_size(mut self, size: VideoSize) -> Self {
self.body = self.body.with_size(size);
self
}
pub fn with_fps(mut self, fps: Fps) -> Self {
self.body = self.body.with_fps(fps);
self
}
pub fn with_duration(mut self, duration: VideoDuration) -> Self {
self.body = self.body.with_duration(duration);
self
}
pub fn with_request_id(mut self, request_id: String) -> Self {
self.body = self.body.with_request_id(request_id);
self
}
pub fn with_user_id(mut self, user_id: String) -> Self {
self.body = self.body.with_user_id(user_id);
self
}
}
impl<N> VideoGenRequest<N>
where
N: ModelName + VideoGen + Serialize,
{
pub fn validate(&self) -> crate::ZaiResult<()> {
self.body
.validate()
.map_err(crate::client::error::ZaiError::from)?;
Ok(())
}
}
impl<N> HttpClient for VideoGenRequest<N>
where
N: ModelName + VideoGen + Serialize,
{
type Body = VideoBody<N>;
type ApiUrl = &'static str;
type ApiKey = String;
fn api_url(&self) -> &Self::ApiUrl {
&"https://open.bigmodel.cn/api/paas/v4/videos/generations"
}
fn api_key(&self) -> &Self::ApiKey {
&self.key
}
fn body(&self) -> &Self::Body {
&self.body
}
}