dynamo_async_openai/
moderation.rs

1// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3//
4// Based on https://github.com/64bit/async-openai/ by Himanshu Neema
5// Original Copyright (c) 2022 Himanshu Neema
6// Licensed under MIT License (see ATTRIBUTIONS-Rust.md)
7//
8// Modifications Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
9// Licensed under Apache 2.0
10
11use crate::{
12    Client,
13    config::Config,
14    error::OpenAIError,
15    types::{CreateModerationRequest, CreateModerationResponse},
16};
17
18/// Given text and/or image inputs, classifies if those inputs are potentially harmful across several categories.
19///
20/// Related guide: [Moderations](https://platform.openai.com/docs/guides/moderation)
21pub struct Moderations<'c, C: Config> {
22    client: &'c Client<C>,
23}
24
25impl<'c, C: Config> Moderations<'c, C> {
26    pub fn new(client: &'c Client<C>) -> Self {
27        Self { client }
28    }
29
30    /// Classifies if text and/or image inputs are potentially harmful. Learn
31    /// more in the [moderation guide](https://platform.openai.com/docs/guides/moderation).
32    #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
33    pub async fn create(
34        &self,
35        request: CreateModerationRequest,
36    ) -> Result<CreateModerationResponse, OpenAIError> {
37        self.client.post("/moderations", request).await
38    }
39}