async_openai/
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    #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
23    pub async fn create(
24        &self,
25        request: CreateModerationRequest,
26    ) -> Result<CreateModerationResponse, OpenAIError> {
27        self.client.post("/moderations", request).await
28    }
29}