async_openai_alt/
moderation.rs

1use crate::{
2    config::Config,
3    error::OpenAIError,
4    types::{CreateModerationRequest, CreateModerationResponse},
5    Client,
6};
7
8/// Given text and/or image inputs, classifies if those inputs are potentially harmful across several categories.
9///
10/// Related guide: [Moderations](https://platform.openai.com/docs/guides/moderation)
11pub struct Moderations<'c, C: Config> {
12    client: &'c Client<C>,
13}
14
15impl<'c, C: Config> Moderations<'c, C> {
16    pub fn new(client: &'c Client<C>) -> Self {
17        Self { client }
18    }
19
20    /// Classifies if text and/or image inputs are potentially harmful. Learn
21    /// more in the [moderation guide](https://platform.openai.com/docs/guides/moderation).
22    pub async fn create(
23        &self,
24        request: CreateModerationRequest,
25    ) -> Result<CreateModerationResponse, OpenAIError> {
26        self.client.post("/moderations", request).await
27    }
28}