openai_dive 1.4.3

OpenAI Dive is an unofficial async Rust library that allows you to interact with the OpenAI API.
Documentation
use crate::v1::api::Client;
use crate::v1::error::APIError;
use crate::v1::helpers::format_response;
use crate::v1::resources::moderation::{ModerationParameters, ModerationResponse};

pub struct Moderations<'a> {
    pub client: &'a Client,
}

impl Client {
    /// Given some input text, outputs if the model classifies it as potentially harmful across several categories.
    pub fn moderations(&self) -> Moderations<'_> {
        Moderations { client: self }
    }
}

impl Moderations<'_> {
    /// Classifies if text is potentially harmful.
    pub async fn create(
        &self,
        parameters: ModerationParameters,
    ) -> Result<ModerationResponse, APIError> {
        let response = self.client.post("/moderations", &parameters, None).await?;

        let response: ModerationResponse = format_response(response.data)?;

        Ok(response)
    }
}