zai_rs/model/gen_video_async/
data.rs1use serde::Serialize;
2use validator::Validate;
3
4use super::{
5 super::traits::*,
6 video_request::{Fps, ImageUrl, VideoBody, VideoDuration, VideoQuality, VideoSize},
7};
8use crate::client::http::HttpClient;
9
10pub struct VideoGenRequest<N>
13where
14 N: ModelName + VideoGen + Serialize,
15{
16 pub key: String,
18 body: VideoBody<N>,
20}
21
22impl<N> VideoGenRequest<N>
23where
24 N: ModelName + VideoGen + Serialize,
25{
26 pub fn new(model: N, key: String) -> Self {
33 let body = VideoBody::new(model);
34 Self { key, body }
35 }
36
37 pub fn with_prompt(mut self, prompt: impl Into<String>) -> Self {
39 self.body = self.body.with_prompt(prompt);
40 self
41 }
42
43 pub fn with_quality(mut self, quality: VideoQuality) -> Self {
45 self.body = self.body.with_quality(quality);
46 self
47 }
48
49 pub fn with_audio(mut self, with_audio: bool) -> Self {
51 self.body = self.body.with_audio(with_audio);
52 self
53 }
54
55 pub fn with_watermark_enabled(mut self, watermark_enabled: bool) -> Self {
57 self.body = self.body.with_watermark_enabled(watermark_enabled);
58 self
59 }
60
61 pub fn with_image_url(mut self, image_url: ImageUrl) -> Self {
63 self.body = self.body.with_image_url(image_url);
64 self
65 }
66
67 pub fn with_size(mut self, size: VideoSize) -> Self {
69 self.body = self.body.with_size(size);
70 self
71 }
72
73 pub fn with_fps(mut self, fps: Fps) -> Self {
75 self.body = self.body.with_fps(fps);
76 self
77 }
78
79 pub fn with_duration(mut self, duration: VideoDuration) -> Self {
81 self.body = self.body.with_duration(duration);
82 self
83 }
84
85 pub fn with_request_id(mut self, request_id: String) -> Self {
87 self.body = self.body.with_request_id(request_id);
88 self
89 }
90
91 pub fn with_user_id(mut self, user_id: String) -> Self {
93 self.body = self.body.with_user_id(user_id);
94 self
95 }
96}
97
98impl<N> VideoGenRequest<N>
99where
100 N: ModelName + VideoGen + Serialize,
101{
102 pub fn validate(&self) -> crate::ZaiResult<()> {
104 self.body
105 .validate()
106 .map_err(crate::client::error::ZaiError::from)?;
107 Ok(())
108 }
109}
110
111impl<N> HttpClient for VideoGenRequest<N>
112where
113 N: ModelName + VideoGen + Serialize,
114{
115 type Body = VideoBody<N>;
116 type ApiUrl = &'static str;
118 type ApiKey = String;
120
121 fn api_url(&self) -> &Self::ApiUrl {
123 &"https://open.bigmodel.cn/api/paas/v4/videos/generations"
124 }
125
126 fn api_key(&self) -> &Self::ApiKey {
128 &self.key
129 }
130
131 fn body(&self) -> &Self::Body {
133 &self.body
134 }
135}