openai_rust_sdk/models/moderations/
request.rs

1//! Request structures for the moderations API
2
3use super::ModerationInput;
4use crate::{De, Ser};
5
6/// Request for content moderation
7#[derive(Debug, Clone, Ser, De)]
8pub struct ModerationRequest {
9    /// Input text to moderate (string or array of strings)
10    pub input: ModerationInput,
11
12    /// ID of the model to use (e.g., "text-moderation-stable", "text-moderation-latest")
13    #[serde(skip_serializing_if = "Option::is_none")]
14    pub model: Option<String>,
15}
16
17impl ModerationRequest {
18    /// Create a new moderation request with a single string
19    pub fn new(input: impl Into<String>) -> Self {
20        Self {
21            input: ModerationInput::String(input.into()),
22            model: None,
23        }
24    }
25
26    /// Create a new moderation request with multiple strings
27    #[must_use]
28    pub fn new_batch(inputs: Vec<String>) -> Self {
29        Self {
30            input: ModerationInput::StringArray(inputs),
31            model: None,
32        }
33    }
34
35    /// Set the model to use for moderation
36    pub fn with_model(mut self, model: impl Into<String>) -> Self {
37        self.model = Some(model.into());
38        self
39    }
40}