zai_rs/model/gen_video_async/
data.rs1use super::super::traits::*;
2use super::video_request::{Fps, ImageUrl, VideoBody, VideoDuration, VideoQuality, VideoSize};
3use crate::client::http::HttpClient;
4use serde::Serialize;
5use validator::Validate;
6
7pub struct VideoGenRequest<N>
10where
11 N: ModelName + VideoGen + Serialize,
12{
13 pub key: String,
15 body: VideoBody<N>,
17}
18
19impl<N> VideoGenRequest<N>
20where
21 N: ModelName + VideoGen + Serialize,
22{
23 pub fn new(model: N, key: String) -> Self {
30 let body = VideoBody::new(model);
31 Self { key, body }
32 }
33
34 pub fn with_prompt(mut self, prompt: impl Into<String>) -> Self {
36 self.body = self.body.with_prompt(prompt);
37 self
38 }
39
40 pub fn with_quality(mut self, quality: VideoQuality) -> Self {
42 self.body = self.body.with_quality(quality);
43 self
44 }
45
46 pub fn with_audio(mut self, with_audio: bool) -> Self {
48 self.body = self.body.with_audio(with_audio);
49 self
50 }
51
52 pub fn with_watermark_enabled(mut self, watermark_enabled: bool) -> Self {
54 self.body = self.body.with_watermark_enabled(watermark_enabled);
55 self
56 }
57
58 pub fn with_image_url(mut self, image_url: ImageUrl) -> Self {
60 self.body = self.body.with_image_url(image_url);
61 self
62 }
63
64 pub fn with_size(mut self, size: VideoSize) -> Self {
66 self.body = self.body.with_size(size);
67 self
68 }
69
70 pub fn with_fps(mut self, fps: Fps) -> Self {
72 self.body = self.body.with_fps(fps);
73 self
74 }
75
76 pub fn with_duration(mut self, duration: VideoDuration) -> Self {
78 self.body = self.body.with_duration(duration);
79 self
80 }
81
82 pub fn with_request_id(mut self, request_id: String) -> Self {
84 self.body = self.body.with_request_id(request_id);
85 self
86 }
87
88 pub fn with_user_id(mut self, user_id: String) -> Self {
90 self.body = self.body.with_user_id(user_id);
91 self
92 }
93}
94
95impl<N> VideoGenRequest<N>
96where
97 N: ModelName + VideoGen + Serialize,
98{
99 pub fn validate(&self) -> anyhow::Result<()> {
101 self.body.validate().map_err(|e| anyhow::anyhow!(e))?;
102 Ok(())
103 }
104}
105
106impl<N> HttpClient for VideoGenRequest<N>
107where
108 N: ModelName + VideoGen + Serialize,
109{
110 type Body = VideoBody<N>;
111 type ApiUrl = &'static str;
113 type ApiKey = String;
115
116 fn api_url(&self) -> &Self::ApiUrl {
118 &"https://open.bigmodel.cn/api/paas/v4/videos/generations"
119 }
120
121 fn api_key(&self) -> &Self::ApiKey {
123 &self.key
124 }
125
126 fn body(&self) -> &Self::Body {
128 &self.body
129 }
130}