zai_rs/model/moderation/
data.rs1use super::models::*;
4use crate::client::ZaiClient;
5
6pub struct Moderation {
11 body: ModerationRequest,
13}
14
15impl Moderation {
16 pub fn new_text(text: impl Into<String>) -> Self {
20 let body = ModerationRequest::new_text(text);
21 Self { body }
22 }
23
24 pub fn new_multimedia(content_type: MediaType, url: impl Into<String>) -> Self {
26 let body = ModerationRequest::new_multimedia(content_type, url);
27 Self { body }
28 }
29
30 pub fn new_items(items: Vec<ModerationItem>) -> Self {
32 Self {
33 body: ModerationRequest::new_items(items),
34 }
35 }
36
37 pub fn body_mut(&mut self) -> &mut ModerationRequest {
39 &mut self.body
40 }
41
42 pub fn validate(&self) -> crate::ZaiResult<()> {
44 self.body
45 .validate()
46 .map_err(crate::client::error::ZaiError::from)?;
47 Ok(())
48 }
49
50 pub async fn send_via(&self, client: &ZaiClient) -> crate::ZaiResult<ModerationResponse> {
55 self.validate()?;
56 let route = crate::client::routes::MODERATION_CHECK;
57 let url = client.endpoints().resolve_route(route, &[])?;
58 client
59 .send_json::<_, ModerationResponse>(route.method(), url, &self.body)
60 .await
61 }
62}