Skip to main content

zai_rs/model/audio_to_text/
request.rs

1use serde::Serialize;
2use validator::Validate;
3
4use super::super::traits::*;
5
6/// Body parameters holder for audio transcription (used to build multipart
7/// form)
8#[derive(Debug, Clone, Serialize, Validate)]
9pub struct AudioToTextBody<N>
10where
11    N: ModelName + AudioToText + Serialize,
12{
13    /// Model code (e.g., glm-asr)
14    pub model: N,
15
16    /// Sampling temperature [0.0, 1.0], default 0.95
17    #[serde(skip_serializing_if = "Option::is_none")]
18    #[validate(range(min = 0.0, max = 1.0))]
19    pub temperature: Option<f32>,
20
21    /// Stream mode flag (sync call should keep false or omit)
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub stream: Option<bool>,
24
25    /// Client-provided unique request id
26    #[serde(skip_serializing_if = "Option::is_none")]
27    pub request_id: Option<String>,
28
29    /// End user id (6..=128 chars)
30    #[serde(skip_serializing_if = "Option::is_none")]
31    #[validate(length(min = 6, max = 128))]
32    pub user_id: Option<String>,
33}
34
35impl<N> AudioToTextBody<N>
36where
37    N: ModelName + AudioToText + Serialize,
38{
39    pub fn new(model: N) -> Self {
40        Self {
41            model,
42            temperature: None,
43            stream: None,
44            request_id: None,
45            user_id: None,
46        }
47    }
48
49    pub fn with_temperature(mut self, temperature: f32) -> Self {
50        self.temperature = Some(temperature);
51        self
52    }
53
54    pub fn with_stream(mut self, stream: bool) -> Self {
55        self.stream = Some(stream);
56        self
57    }
58
59    pub fn with_request_id(mut self, request_id: impl Into<String>) -> Self {
60        self.request_id = Some(request_id.into());
61        self
62    }
63
64    pub fn with_user_id(mut self, user_id: impl Into<String>) -> Self {
65        self.user_id = Some(user_id.into());
66        self
67    }
68}